【问题标题】:Error parsing HTTP request header HTTP method names must be tokens with HTTPS spring Boot tomcat解析HTTP请求头时出错HTTP方法名称必须是带有HTTPS spring Boot tomcat的令牌
【发布时间】:2021-02-07 13:21:31
【问题描述】:

我正在尝试在运行在 tomcat 9.0.39 上的 Spring Boot 应用程序中配置 HTTPS,但是当我在 PostmanCanary 中执行 POST 时,我在 console.log 中收到此错误:

2020-10-24 16:32:12.339  INFO 22073 --- [nio-8081-exec-4] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x000xf70x010x000x000xf30x030x030xb1Z0xba`0xd2q0xb10xa40xcdGk>.H0x190x0f0xe90xe20xeb0xbdJ80xc1l0y0xaa0x050x17'0x060xda]. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:417) ~[tomcat-coyote.jar:9.0.39]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:261) ~[tomcat-coyote.jar:9.0.39]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-coyote.jar:9.0.39]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-coyote.jar:9.0.39]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-coyote.jar:9.0.39]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-coyote.jar:9.0.39]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-util.jar:9.0.39]
    at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

在 PostmanCanary 中,除了这个 tomcat 错误,我还收到:

Error: write EPROTO 37322838446536:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:

我的 postmanCanary 在设置客户端证书中导入了证书(我已在 PFX 文件选项中导入了我的 .p12)

我的 server.xml 有这样的评论:

<!--APR library loader. Documentation at /docs/apr.html 
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>-->

还有这个:

<Connector port="8081" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" debug="0" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreType="PKCS12" keystoreFile="/home/...PATH_TO_P12.../base.p12" keystorePass="mypassword" truststoreType="PKCS12" truststoreFile="base.p12" truststorePass="mypassword" />

我的申请:

@ComponentScan("com.xxx.base")
@EntityScan("com.xxx.base.domain")
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@SpringBootApplication
public class UserRegistryApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(UserRegistryApplication.class, args);
    }
    
     @Override
     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(UserRegistryApplication.class);
     }
}

我的安全配置(我不想进行身份验证,这是第一个用户注册表,所以还没有登录,我只想以安全的方式使用用户密码传递我的 POST 正文)

@Configuration
@EnableWebSecurity
public class BasicConfiguration extends WebSecurityConfigurerAdapter{
    
     @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
              .authorizeRequests()
              .anyRequest()
              .authenticated()
              .and()
              .httpBasic();
        }

}

我的 application.properties(base.p12 在具有属性的资源中):

server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:base.p12
server.ssl.key-store-password=mypassword
server.ssl.key-alias=base
server.ssl.enabled=true

我的控制器:

    //POST /User {...} --> create not active User prototype
    @PostMapping("/createPrototype")
    public ResponseEntity<User> createUserPrototype(@RequestBody User requestUser) throws HttpClientErrorException, URISyntaxException, Exception{
        ...codes...

}

有人知道我错过了什么吗?

【问题讨论】:

    标签: spring-boot tomcat https postman


    【解决方案1】:

    我自己解决了。

    首先我使用这些命令生成了另一个 .p12:

    openssl req -x509 -newkey rsa:4096 -keyout base.pem -out base.pem -days 365 -nodes

    openssl pkcs12 -export -out base.p12 -inkey base.pem -in base.pem

    然后,在我的 server.xml 中取消注释:

    <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
    

    然后把他的:

    <Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol"
    maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
    keystoreFile="/home/...PATH_TO_P12.../base.p12"
    keystorePass="password" clientAuth="false" sslProtocol="TLS"
    keystoreType="PKCS12" />
    

    我的配置现在是这样的:

    @Override
        protected void configure(HttpSecurity http) throws Exception {
            //http.authorizeRequests().anyRequest().authenticated().and()
              http.csrf().disable().httpBasic();
              
        }
    

    在我的邮递员中,我在设置中禁用了 SSL 证书验证

    现在可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 2021-01-20
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      • 2021-06-28
      相关资源
      最近更新 更多