20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package sun.security.pkcs10;
28
29 import java.io.PrintStream;
30 import java.io.IOException;
31 import java.math.BigInteger;
32
33 import java.security.cert.CertificateException;
34 import java.security.NoSuchAlgorithmException;
35 import java.security.InvalidKeyException;
36 import java.security.Signature;
37 import java.security.SignatureException;
38 import java.security.PublicKey;
39
40 import sun.misc.BASE64Encoder;
41
42 import sun.security.util.*;
43 import sun.security.x509.AlgorithmId;
44 import sun.security.x509.X509Key;
45 import sun.security.x509.X500Name;
46
47 /**
48 * A PKCS #10 certificate request is created and sent to a Certificate
49 * Authority, which then creates an X.509 certificate and returns it to
50 * the entity that requested it. A certificate request basically consists
51 * of the subject's X.500 name, public key, and optionally some attributes,
52 * signed using the corresponding private key.
53 *
54 * The ASN.1 syntax for a Certification Request is:
55 * <pre>
56 * CertificationRequest ::= SEQUENCE {
57 * certificationRequestInfo CertificationRequestInfo,
58 * signatureAlgorithm SignatureAlgorithmIdentifier,
59 * signature Signature
60 * }
272
273 /**
274 * Prints an E-Mailable version of the certificate request on the print
275 * stream passed. The format is a common base64 encoded one, supported
276 * by most Certificate Authorities because Netscape web servers have
277 * used this for some time. Some certificate authorities expect some
278 * more information, in particular contact information for the web
279 * server administrator.
280 *
281 * @param out the print stream where the certificate request
282 * will be printed.
283 * @exception IOException when an output operation failed
284 * @exception SignatureException when the certificate request was
285 * not yet signed.
286 */
287 public void print(PrintStream out)
288 throws IOException, SignatureException {
289 if (encoded == null)
290 throw new SignatureException("Cert request was not signed");
291
292 BASE64Encoder encoder = new BASE64Encoder();
293
294 out.println("-----BEGIN NEW CERTIFICATE REQUEST-----");
295 encoder.encodeBuffer(encoded, out);
296 out.println("-----END NEW CERTIFICATE REQUEST-----");
297 }
298
299 /**
300 * Provides a short description of this request.
301 */
302 public String toString() {
303 return "[PKCS #10 certificate request:\n"
304 + subjectPublicKeyInfo.toString()
305 + " subject: <" + subject + ">" + "\n"
306 + " attributes: " + attributeSet.toString()
307 + "\n]";
308 }
309
310 /**
311 * Compares this object for equality with the specified
312 * object. If the <code>other</code> object is an
313 * <code>instanceof</code> <code>PKCS10</code>, then
314 * its encoded form is retrieved and compared with the
315 * encoded form of this certificate request.
|
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package sun.security.pkcs10;
28
29 import java.io.PrintStream;
30 import java.io.IOException;
31 import java.math.BigInteger;
32
33 import java.security.cert.CertificateException;
34 import java.security.NoSuchAlgorithmException;
35 import java.security.InvalidKeyException;
36 import java.security.Signature;
37 import java.security.SignatureException;
38 import java.security.PublicKey;
39
40 import java.util.Base64;
41
42 import sun.security.util.*;
43 import sun.security.x509.AlgorithmId;
44 import sun.security.x509.X509Key;
45 import sun.security.x509.X500Name;
46
47 /**
48 * A PKCS #10 certificate request is created and sent to a Certificate
49 * Authority, which then creates an X.509 certificate and returns it to
50 * the entity that requested it. A certificate request basically consists
51 * of the subject's X.500 name, public key, and optionally some attributes,
52 * signed using the corresponding private key.
53 *
54 * The ASN.1 syntax for a Certification Request is:
55 * <pre>
56 * CertificationRequest ::= SEQUENCE {
57 * certificationRequestInfo CertificationRequestInfo,
58 * signatureAlgorithm SignatureAlgorithmIdentifier,
59 * signature Signature
60 * }
272
273 /**
274 * Prints an E-Mailable version of the certificate request on the print
275 * stream passed. The format is a common base64 encoded one, supported
276 * by most Certificate Authorities because Netscape web servers have
277 * used this for some time. Some certificate authorities expect some
278 * more information, in particular contact information for the web
279 * server administrator.
280 *
281 * @param out the print stream where the certificate request
282 * will be printed.
283 * @exception IOException when an output operation failed
284 * @exception SignatureException when the certificate request was
285 * not yet signed.
286 */
287 public void print(PrintStream out)
288 throws IOException, SignatureException {
289 if (encoded == null)
290 throw new SignatureException("Cert request was not signed");
291
292
293 out.println("-----BEGIN NEW CERTIFICATE REQUEST-----");
294 String base64EncodedCertString = Base64.getMimeEncoder().encodeToString(encoded);
295 out.println(base64EncodedCertString);
296 //out.println(Base64.getMimeEncoder().encodeToString(encoded));
297 out.println("-----END NEW CERTIFICATE REQUEST-----");
298 }
299
300 /**
301 * Provides a short description of this request.
302 */
303 public String toString() {
304 return "[PKCS #10 certificate request:\n"
305 + subjectPublicKeyInfo.toString()
306 + " subject: <" + subject + ">" + "\n"
307 + " attributes: " + attributeSet.toString()
308 + "\n]";
309 }
310
311 /**
312 * Compares this object for equality with the specified
313 * object. If the <code>other</code> object is an
314 * <code>instanceof</code> <code>PKCS10</code>, then
315 * its encoded form is retrieved and compared with the
316 * encoded form of this certificate request.
|