1 /* |
|
2 * Copyright 1996-2003 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package sun.security.x509; |
|
27 |
|
28 import java.security.Signature; |
|
29 import java.security.SignatureException; |
|
30 import java.security.Signer; |
|
31 import java.security.NoSuchAlgorithmException; |
|
32 |
|
33 /** |
|
34 * This class provides a binding between a Signature object and an |
|
35 * authenticated X.500 name (from an X.509 certificate chain), which |
|
36 * is needed in many public key signing applications. |
|
37 * |
|
38 * <P>The name of the signer is important, both because knowing it is the |
|
39 * whole point of the signature, and because the associated X.509 certificate |
|
40 * is always used to verify the signature. |
|
41 * |
|
42 * <P><em>The X.509 certificate chain is temporarily not associated with |
|
43 * the signer, but this omission will be resolved.</em> |
|
44 * |
|
45 * |
|
46 * @author David Brownell |
|
47 * @author Amit Kapoor |
|
48 * @author Hemma Prafullchandra |
|
49 */ |
|
50 public final class X500Signer extends Signer |
|
51 { |
|
52 private static final long serialVersionUID = -8609982645394364834L; |
|
53 |
|
54 /** |
|
55 * Called for each chunk of the data being signed. That |
|
56 * is, you can present the data in many chunks, so that |
|
57 * it doesn't need to be in a single sequential buffer. |
|
58 * |
|
59 * @param buf buffer holding the next chunk of the data to be signed |
|
60 * @param offset starting point of to-be-signed data |
|
61 * @param len how many bytes of data are to be signed |
|
62 * @exception SignatureException on errors. |
|
63 */ |
|
64 public void update(byte buf[], int offset, int len) |
|
65 throws SignatureException { |
|
66 sig.update (buf, offset, len); |
|
67 } |
|
68 |
|
69 /** |
|
70 * Produces the signature for the data processed by update(). |
|
71 * |
|
72 * @exception SignatureException on errors. |
|
73 */ |
|
74 public byte[] sign() throws SignatureException { |
|
75 return sig.sign(); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Returns the algorithm used to sign. |
|
80 */ |
|
81 public AlgorithmId getAlgorithmId() { |
|
82 return algid; |
|
83 } |
|
84 |
|
85 /** |
|
86 * Returns the name of the signing agent. |
|
87 */ |
|
88 public X500Name getSigner() { |
|
89 return agent; |
|
90 } |
|
91 |
|
92 /* |
|
93 * Constructs a binding between a signature and an X500 name |
|
94 * from an X.509 certificate. |
|
95 */ |
|
96 // package private ----hmmmmm ????? |
|
97 public X500Signer(Signature sig, X500Name agent) { |
|
98 if (sig == null || agent == null) |
|
99 throw new IllegalArgumentException ("null parameter"); |
|
100 |
|
101 this.sig = sig; |
|
102 this.agent = agent; |
|
103 |
|
104 try { |
|
105 this.algid = AlgorithmId.getAlgorithmId(sig.getAlgorithm()); |
|
106 |
|
107 } catch (NoSuchAlgorithmException e) { |
|
108 throw new RuntimeException("internal error! " + e.getMessage()); |
|
109 } |
|
110 } |
|
111 |
|
112 private Signature sig; |
|
113 private X500Name agent; // XXX should be X509CertChain |
|
114 private AlgorithmId algid; |
|
115 } |
|