Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple key usages to a certificate when using Java keytool

I am trying to add multiple key usages to a certificate when using java keytool to generate the certificate. It is only picking up the last one listed.

keytool -genkeypair -keystore keystore.jks -validity 3650 -alias test 
        -keysize 2048 -keyalg RSA -storetype JKS 
        -ext KeyUsage=digitalSignature -ext KeyUsage=keyEncipherment 
         -ext KeyUsage=keyCertSign

The documentation says you can use the -ext argument many times. What am I doing wrong?

like image 528
user3375401 Avatar asked Sep 02 '25 16:09

user3375401


1 Answers

The -ext can be given multiple times, but not for the same type of extension. What you want is

keytool -genkeypair -keystore keystore.jks -validity 3650 -alias test 
    -keysize 2048 -keyalg RSA -storetype JKS 
    -ext KeyUsage=digitalSignature,keyEncipherment,keyCertSign

Multiple -ext are used to define extensions of different type separately. For example like this:

keytool -genkeypair -keystore keystore.jks -validity 3650 -alias test
    -keysize 2048 -keyalg RSA -storetype JKS
    -ext KeyUsage=digitalSignature,keyEncipherment,keyCertSign
    -ext ExtendedKeyUsage=serverAuth,clientAuth
    -ext BasicConstraints=ca:true,PathLen:3
    -ext SubjectAlternativeName=DNS:foo.bar.com,EMAIL:[email protected]
    -ext CRLDistributionPoints=URI:http://foo.bar.com/ca.crl

this is a contrived example, but you get the idea.

like image 118
wallenborn Avatar answered Sep 04 '25 04:09

wallenborn