openssl-rsautl.pod.in 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. =pod
  2. =begin comment
  3. {- join("\n", @autowarntext) -}
  4. =end comment
  5. =head1 NAME
  6. openssl-rsautl - RSA utility
  7. =head1 SYNOPSIS
  8. B<openssl> B<rsautl>
  9. [B<-help>]
  10. [B<-in> I<file>]
  11. [B<-out> I<file>]
  12. [B<-inkey> I<file>]
  13. [B<-keyform> B<DER>|B<PEM>|B<ENGINE>]
  14. [B<-pubin>]
  15. [B<-certin>]
  16. [B<-sign>]
  17. [B<-verify>]
  18. [B<-encrypt>]
  19. [B<-decrypt>]
  20. [B<-pkcs>]
  21. [B<-ssl>]
  22. [B<-raw>]
  23. [B<-hexdump>]
  24. [B<-asn1parse>]
  25. {- $OpenSSL::safe::opt_r_synopsis -}
  26. =for openssl ifdef engine
  27. =head1 DESCRIPTION
  28. This command can be used to sign, verify, encrypt and decrypt
  29. data using the RSA algorithm.
  30. =head1 OPTIONS
  31. =over 4
  32. =item B<-help>
  33. Print out a usage message.
  34. =item B<-in> I<filename>
  35. This specifies the input filename to read data from or standard input
  36. if this option is not specified.
  37. =item B<-out> I<filename>
  38. Specifies the output filename to write to or standard output by
  39. default.
  40. =item B<-inkey> I<file>
  41. The input key file, by default it should be an RSA private key.
  42. =item B<-keyform> B<DER>|B<PEM>|B<ENGINE>
  43. The key format; the default is B<PEM>.
  44. See L<openssl(1)/Format Options> for details.
  45. =item B<-pubin>
  46. The input file is an RSA public key.
  47. =item B<-certin>
  48. The input is a certificate containing an RSA public key.
  49. =item B<-sign>
  50. Sign the input data and output the signed result. This requires
  51. an RSA private key.
  52. =item B<-verify>
  53. Verify the input data and output the recovered data.
  54. =item B<-encrypt>
  55. Encrypt the input data using an RSA public key.
  56. =item B<-decrypt>
  57. Decrypt the input data using an RSA private key.
  58. =item B<-pkcs>, B<-oaep>, B<-ssl>, B<-raw>
  59. The padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
  60. special padding used in SSL v2 backwards compatible handshakes,
  61. or no padding, respectively.
  62. For signatures, only B<-pkcs> and B<-raw> can be used.
  63. =item B<-hexdump>
  64. Hex dump the output data.
  65. =item B<-asn1parse>
  66. Parse the ASN.1 output data, this is useful when combined with the
  67. B<-verify> option.
  68. {- $OpenSSL::safe::opt_r_item -}
  69. =back
  70. =head1 NOTES
  71. Since this command uses the RSA algorithm directly, it can only be
  72. used to sign or verify small pieces of data.
  73. =head1 EXAMPLES
  74. Sign some data using a private key:
  75. openssl rsautl -sign -in file -inkey key.pem -out sig
  76. Recover the signed data
  77. openssl rsautl -verify -in sig -inkey key.pem
  78. Examine the raw signed data:
  79. openssl rsautl -verify -in sig -inkey key.pem -raw -hexdump
  80. 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  81. 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  82. 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  83. 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  84. 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  85. 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  86. 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  87. 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64 .....hello world
  88. The PKCS#1 block formatting is evident from this. If this was done using
  89. encrypt and decrypt the block would have been of type 2 (the second byte)
  90. and random padding data visible instead of the 0xff bytes.
  91. It is possible to analyse the signature of certificates using this
  92. utility in conjunction with L<openssl-asn1parse(1)>. Consider the self signed
  93. example in F<certs/pca-cert.pem>. Running L<openssl-asn1parse(1)> as follows
  94. yields:
  95. openssl asn1parse -in pca-cert.pem
  96. 0:d=0 hl=4 l= 742 cons: SEQUENCE
  97. 4:d=1 hl=4 l= 591 cons: SEQUENCE
  98. 8:d=2 hl=2 l= 3 cons: cont [ 0 ]
  99. 10:d=3 hl=2 l= 1 prim: INTEGER :02
  100. 13:d=2 hl=2 l= 1 prim: INTEGER :00
  101. 16:d=2 hl=2 l= 13 cons: SEQUENCE
  102. 18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
  103. 29:d=3 hl=2 l= 0 prim: NULL
  104. 31:d=2 hl=2 l= 92 cons: SEQUENCE
  105. 33:d=3 hl=2 l= 11 cons: SET
  106. 35:d=4 hl=2 l= 9 cons: SEQUENCE
  107. 37:d=5 hl=2 l= 3 prim: OBJECT :countryName
  108. 42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU
  109. ....
  110. 599:d=1 hl=2 l= 13 cons: SEQUENCE
  111. 601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
  112. 612:d=2 hl=2 l= 0 prim: NULL
  113. 614:d=1 hl=3 l= 129 prim: BIT STRING
  114. The final BIT STRING contains the actual signature. It can be extracted with:
  115. openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
  116. The certificate public key can be extracted with:
  117. openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem
  118. The signature can be analysed with:
  119. openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
  120. 0:d=0 hl=2 l= 32 cons: SEQUENCE
  121. 2:d=1 hl=2 l= 12 cons: SEQUENCE
  122. 4:d=2 hl=2 l= 8 prim: OBJECT :md5
  123. 14:d=2 hl=2 l= 0 prim: NULL
  124. 16:d=1 hl=2 l= 16 prim: OCTET STRING
  125. 0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5 .F...Js.7...H%..
  126. This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
  127. the digest used was md5. The actual part of the certificate that was signed can
  128. be extracted with:
  129. openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
  130. and its digest computed with:
  131. openssl md5 -c tbs
  132. MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
  133. which it can be seen agrees with the recovered value above.
  134. =head1 SEE ALSO
  135. L<openssl(1)>,
  136. L<openssl-dgst(1)>,
  137. L<openssl-rsa(1)>,
  138. L<openssl-genrsa(1)>
  139. =head1 COPYRIGHT
  140. Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
  141. Licensed under the Apache License 2.0 (the "License"). You may not use
  142. this file except in compliance with the License. You can obtain a copy
  143. in the file LICENSE in the source distribution or at
  144. L<https://www.openssl.org/source/license.html>.
  145. =cut