rsautl.pod 5.3 KB
Newer Older
D
Dr. Stephen Henson 已提交
1 2 3 4 5 6 7 8 9
=pod

=head1 NAME

rsautl - RSA utility

=head1 SYNOPSIS

B<openssl> B<rsautl>
10
[B<-help>]
D
Dr. Stephen Henson 已提交
11 12 13
[B<-in file>]
[B<-out file>]
[B<-inkey file>]
14
[B<-keyform PEM|DER|ENGINE>]
D
Dr. Stephen Henson 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
[B<-pubin>]
[B<-certin>]
[B<-sign>]
[B<-verify>]
[B<-encrypt>]
[B<-decrypt>]
[B<-pkcs>]
[B<-ssl>]
[B<-raw>]
[B<-hexdump>]
[B<-asn1parse>]

=head1 DESCRIPTION

The B<rsautl> command can be used to sign, verify, encrypt and decrypt
data using the RSA algorithm.

R
Rich Salz 已提交
32
=head1 OPTIONS
D
Dr. Stephen Henson 已提交
33 34 35

=over 4

36 37 38 39
=item B<-help>

Print out a usage message.

D
Dr. Stephen Henson 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53
=item B<-in filename>

This specifies the input filename to read data from or standard input
if this option is not specified.

=item B<-out filename>

specifies the output filename to write to or standard output by
default.

=item B<-inkey file>

the input key file, by default it should be an RSA private key.

54 55 56 57
=item B<-keyform PEM|DER|ENGINE>

the key format PEM, DER or ENGINE.

D
Dr. Stephen Henson 已提交
58 59
=item B<-pubin>

60
the input file is an RSA public key.
D
Dr. Stephen Henson 已提交
61 62 63

=item B<-certin>

R
Rich Salz 已提交
64
the input is a certificate containing an RSA public key.
D
Dr. Stephen Henson 已提交
65 66 67 68

=item B<-sign>

sign the input data and output the signed result. This requires
S
Soheil Rashidi 已提交
69
an RSA private key.
D
Dr. Stephen Henson 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82

=item B<-verify>

verify the input data and output the recovered data.

=item B<-encrypt>

encrypt the input data using an RSA public key.

=item B<-decrypt>

decrypt the input data using an RSA private key.

B
Bodo Möller 已提交
83
=item B<-pkcs, -oaep, -ssl, -raw>
D
Dr. Stephen Henson 已提交
84

B
Bodo Möller 已提交
85 86 87 88
the padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
special padding used in SSL v2 backwards compatible handshakes,
or no padding, respectively.
For signatures, only B<-pkcs> and B<-raw> can be used.
D
Dr. Stephen Henson 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

=item B<-hexdump>

hex dump the output data.

=item B<-asn1parse>

asn1parse the output data, this is useful when combined with the
B<-verify> option.

=back

=head1 NOTES

B<rsautl> because it uses the RSA algorithm directly can only be
used to sign or verify small pieces of data.

=head1 EXAMPLES

B
Bodo Möller 已提交
108
Sign some data using a private key:
D
Dr. Stephen Henson 已提交
109 110 111 112 113

 openssl rsautl -sign -in file -inkey key.pem -out sig

Recover the signed data

114
 openssl rsautl -verify -in sig -inkey key.pem
D
Dr. Stephen Henson 已提交
115 116 117

Examine the raw signed data:

118
 openssl rsautl -verify -in file -inkey key.pem -raw -hexdump
D
Dr. Stephen Henson 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64   .....hello world

The PKCS#1 block formatting is evident from this. If this was done using
encrypt and decrypt the block would have been of type 2 (the second byte)
and random padding data visible instead of the 0xff bytes.

It is possible to analyse the signature of certificates using this
utility in conjunction with B<asn1parse>. Consider the self signed
example in certs/pca-cert.pem . Running B<asn1parse> as follows yields:

 openssl asn1parse -in pca-cert.pem

R
Rich Salz 已提交
139 140 141
    0:d=0  hl=4 l= 742 cons: SEQUENCE
    4:d=1  hl=4 l= 591 cons:  SEQUENCE
    8:d=2  hl=2 l=   3 cons:   cont [ 0 ]
D
Dr. Stephen Henson 已提交
142 143
   10:d=3  hl=2 l=   1 prim:    INTEGER           :02
   13:d=2  hl=2 l=   1 prim:   INTEGER           :00
R
Rich Salz 已提交
144
   16:d=2  hl=2 l=  13 cons:   SEQUENCE
D
Dr. Stephen Henson 已提交
145
   18:d=3  hl=2 l=   9 prim:    OBJECT            :md5WithRSAEncryption
R
Rich Salz 已提交
146 147 148 149
   29:d=3  hl=2 l=   0 prim:    NULL
   31:d=2  hl=2 l=  92 cons:   SEQUENCE
   33:d=3  hl=2 l=  11 cons:    SET
   35:d=4  hl=2 l=   9 cons:     SEQUENCE
D
Dr. Stephen Henson 已提交
150 151 152
   37:d=5  hl=2 l=   3 prim:      OBJECT            :countryName
   42:d=5  hl=2 l=   2 prim:      PRINTABLESTRING   :AU
  ....
R
Rich Salz 已提交
153
  599:d=1  hl=2 l=  13 cons:  SEQUENCE
D
Dr. Stephen Henson 已提交
154
  601:d=2  hl=2 l=   9 prim:   OBJECT            :md5WithRSAEncryption
R
Rich Salz 已提交
155 156
  612:d=2  hl=2 l=   0 prim:   NULL
  614:d=1  hl=3 l= 129 prim:  BIT STRING
D
Dr. Stephen Henson 已提交
157 158 159 160 161 162 163


The final BIT STRING contains the actual signature. It can be extracted with:

 openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614

The certificate public key can be extracted with:
R
Rich Salz 已提交
164

D
Dr. Stephen Henson 已提交
165
 openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem
D
Dr. Stephen Henson 已提交
166 167 168 169 170

The signature can be analysed with:

 openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin

R
Rich Salz 已提交
171 172
    0:d=0  hl=2 l=  32 cons: SEQUENCE
    2:d=1  hl=2 l=  12 cons:  SEQUENCE
D
Dr. Stephen Henson 已提交
173
    4:d=2  hl=2 l=   8 prim:   OBJECT            :md5
R
Rich Salz 已提交
174 175
   14:d=2  hl=2 l=   0 prim:   NULL
   16:d=1  hl=2 l=  16 prim:  OCTET STRING
D
Dr. Stephen Henson 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
      0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5   .F...Js.7...H%..

This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
the digest used was md5. The actual part of the certificate that was signed can
be extracted with:

 openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4

and its digest computed with:

 openssl md5 -c tbs
 MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5

which it can be seen agrees with the recovered value above.

=head1 SEE ALSO

R
Rich Salz 已提交
193
L<dgst(1)>, L<rsa(1)>, L<genrsa(1)>
194

R
Rich Salz 已提交
195 196 197 198 199 200 201 202 203 204
=head1 COPYRIGHT

Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the OpenSSL license (the "License").  You may not use
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.

=cut