openssl smime -sign -text -in message.txt -out signed-message.txt
-signer <cert> -inkey <key>
openssl smime -encrypt -in signed-mail-message.txt -out encrypted-mail-message.txt destination-user-certificate.pem
openssl smime -decrypt -in received-encrypted-mail-message.txt
-out received-mail-message.txt -recip ${HOME}/.globus/usercert.pem
-inkey ${HOME}/.globus/userkey.pem
openssl smime -verify -text -in received-signed-mail-message.txt -CApath /etc/certificatesThe following example will display the distinguish name (DN) of the signer.
openssl smime -pk7out -in received-signed-mail-message.txt | openssl pkcs7 -print_certs -noout
openssl crl -noout -CApath /etc/grid-security/certificates -in 11b4a5a2.r0 -noout openssl crl -noout -CAfile /etc/grid-security/certificates/11b4a5a2.0 -in 11b4a5a2.r0 -noout
openssl x509 -text -noout -in usercert.pem
openssl crl -text -noout -in /etc/grid-security/certificates/11b4a5a2.r0
openssl s_client -host www.scalene.net -port 443 openssl s_client -connect www.scalene.net:443
openssl x509 -inform PEM -outform DER -in foo.pem -out foo.der
openssl pkcs12 command to extract the key and certificate into a single file containing both the key and certificate in PEM format. Extract the key and certificate with a text editor, copy & paste, etc.
openssl pkcs12 -in foo.p12 -out foo.pemor
openssl pkcs12 -in foo.p12 -out key.pem -nocerts openssl pkcs12 -in foo.p12 -out key.pem -nokeys
openssl rsa -in foo.pem -out foo.pem
openssl pkcs12 -export -in foo-cert.pem -inkey foo-key.pem -out foo.p12
keytool -list -storetype pkcs12 -v -keystore cert.p12The
keytool program is accessing the keystore as pkcs12. You can do this either in your code by including a line similar to:
javax.net.ssl.keyStoreType=pkcs12or you can change the default type by modifying the /keystore.type/ parameter in the
java.security file
$J2SE/jre/lib/security/java.security
openssl req command is used to create a PKCS#10 (Public Key Cryptography Standards) certificate request. It also generates a key pair when -new is specified. The -days switch is used to specify the number of days that the certificate is valid. OpenSSL prompts for a new password for this certificate (e.g. siteKEY). A certificate request may be created as follows:
openssl req -new -keyout newkey.pem -out newreq.pem -days 360 -config openssl.conf
openssl req command with the -x509 switch. The certificate is placed in the file cacert.pem, and the private key in private/cakey.pem. The commonName for the self-signed certificate should be a meaningful string for people to read, and not be the domain name of the server (since the server domain name is needed for server certificates used by Netscape/Mozilla/Safari).
The req command prompts for the password (e.g. caKEY) for the private key, and is used as follows:
openssl req -new -x509 -keyout private/cakey.pem -out private/cacert.pem -config openssl.conf
A server certificate is created by signing the certificate request using the openssl ca command. The -policy switch specifies the section of the OpenSSL configuration file which defines which distinguished name fields are required, and the order of the fields. As an example, our test configuration file specifies the policy_anything section which makes all the listed distinguished name fields optional.
When this command is executed, it prompts for the certificate authority password:
cat newreq.pem newkey.pem > new.pem openssl ca -policy policy_anything -out newcert.pem -config openssl.conf -infiles new.pem
When the Apache-SSL server is used, then the httpd.conf file must also be modified to specify the CA certificate and key files as follows:
# Set the CA certificate verification path (must be PEM encoded). SSLCACertificatePath $SSLDIR/private # Set the CA certificate verification file (must be PEM encoded). SSLCACertificateFile $SSLDIR/private/CAcert.pemTo install the CA certificate, load it using HTTP
Content-Type: application/x-x509-ca-cert. To do this in a manner which does not depend on the server, use a cgi-script like the following example, or save the certificate in a file with a "cacert" suffix and define this suffix in the server configuration file to correspond to the application/x-x509-ca-cert mime type.
The HTML form used to request loading a CA certificate into a browser might be written as follows:
<HEAD><TITLE>Load CA Certificate</title></head><BODY> <H1>Load Certificate Authority Certificate</h1> <FORM ACTION="http://yourserver/cgi-bin/loadCAcert.pl" METHOD=post> <TABLE> <TR> <TD>Netscape Browser (PEM Format):</td> <TD><INPUT TYPE="RADIO" NAME="FORMAT" VALUE="PEM" CHECKED></td> </tr> <TR> <TD>Microsoft Browser (DER Format):</td> <TD><INPUT TYPE="RADIO" NAME="FORMAT" VALUE="DER"></td> </tr> </table> <INPUT TYPE="SUBMIT" VALUE="Load Certificate"> </form> </body>
When this form is submitted, the following CGI script is used to process it and return the result loadCAcert.pl:
#!/usr/bin/perl
require 5.004;
use strict;
use CGI;
my $cert_dir = "$SSLDIR/private";
my $cert_file = "CAcert.pem";
my $query = new CGI;
my $kind = $query->param('FORMAT');
if($kind eq 'DER') { $cert_file = "CAcert.der"; }
my $cert_path = "$cert_dir/$cert_file";
my $data = "";
open(CERT, "<$cert_path");
while(<CERT>) { $data .= $_; }
close(CERT);
print "Content-Type: application/x-x509-ca-cert\n";
print "Content-Length: ", length($data), "\n\n$data";
1;