I use these commands to generate a selfsigned cert:
gmssl ecparam -genkey -name sm2p256v1 -out ca.key
gmssl req -new -key ca.key -out ca.csr
gmssl x509 -req -days 3650 -sm3 -signkey ca.key -in ca.csr -out ca.crt
gmssl ecparam -genkey -name sm2p256v1 -out server.key
gmssl req -new -key server.key -out server.csr
gmssl x509 -req -days 3650 -sm3 -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt
gmssl pkcs12 -export -in server.crt -inkey server.key -out server.p12 -name serverkey
and I input 123456 whenever it saied a password is need to input. but when I try to import server cert and key to a jks file, it doesn't work, I also try to replace some of the password into "changeit" but keytool show the same error:
keytool -importkeystore -deststorepass 123456 -destkeypass 123456 \
-destkeystore server.jks -srckeystore server.p12 -srcstoretype PKCS12 \
-srcstorepass 123456 -alias serverkey
keytool error: java.io.IOException: keystore password was incorrect
some addition details:
reply to the answer of @dave_thompson_085:
thank you so much for answering my question.
actually, I want to build a netty https server using GMSSL, but I'm not familiar with that and I dont find tutorial about how to build a gmssl server using netty, so I want to build a normal SSL server first and than modify it to GMSSL. The tutorial I find to build a SSL server use a jks file, so I try to put SM2 key and cert into it to modify it to GMSSL.
I also find other way use directly cert and key file, like build a SSLContext through these code:
File certChainFile = new File("server.crt");
File keyFile = new File("server.key");
File rootFile = new File("ca.crt");
SslContext sslCtx = SslContextBuilder.forServer(certChainFile, keyFile)
.trustManager(rootFile).protocols("GMSSLv.1.0")
// will it recognize these string "GMSSLv.1.0"? I'dont konw, I just try.
.clientAuth(ClientAuth.NONE).build();
but it throw error when I try to run:
java.lang.IllegalArgumentException: File does not contain valid certificates
I search these error on google, someone said i need to using a pkcs8 cert, so I try this command:
gmssl pkcs8 -topk8 -inform PEM -outform PEM -in server.p12 -out server.p8 -nocrypt
and it doesn't work too:
unable to load key
4577107392:error:25066067:DSO support routines:dlfcn_load:could not load the shared library:crypto/dso/dso_dlfcn.c:113:filename(libproviders.dylib): dlopen(libproviders.dylib, 2): image not found
4577107392:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto/dso/dso_lib.c:161:
4577107392:error:0E07506E:configuration file routines:module_load_dso:error loading dso:crypto/conf/conf_mod.c:220:module=providers, path=providers
4577107392:error:0E076071:configuration file routines:module_run:unknown module name:crypto/conf/conf_mod.c:162:module=providers
4577107392:error:0906D06C:PEM routines:PEM_read_bio:no start line:crypto/pem/pem_lib.c:695:
actually I'm very confuse, I don't know how to use netty to build a gmssl server.
do netty support gmssl and SM2 SM3 SM4 algorithm? I see this issue it seem to support(https://github.com/netty/netty/issues/11406), but it seen that the pull request doesnt imply the encryption algorithm.
how should I do to build a GMSSL server? should I use a special version of JCE, Netty or JDK? or I need to imply the protocol by myself?