annotate src/ch/ethz/ssh2/signature/RSASHA1Verify.java @ 340:82d127ae1550 ganymed

fix pubkey display; better layout for generate pub keys
author Carl Byington <carl@five-ten-sg.com>
date Thu, 31 Jul 2014 15:53:40 -0700
parents db9b028016de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
1
279
e1c445af8e46 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
2 package ch.ethz.ssh2.signature;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 import java.io.IOException;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 import java.math.BigInteger;
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
6 import java.security.InvalidKeyException;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
7 import java.security.KeyFactory;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
8 import java.security.NoSuchAlgorithmException;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
9 import java.security.Signature;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
10 import java.security.SignatureException;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
11 import java.security.interfaces.RSAPrivateKey;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
12 import java.security.interfaces.RSAPublicKey;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
13 import java.security.spec.InvalidKeySpecException;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
14 import java.security.spec.KeySpec;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
15 import java.security.spec.RSAPublicKeySpec;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16
279
e1c445af8e46 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
17 import ch.ethz.ssh2.log.Logger;
e1c445af8e46 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
18 import ch.ethz.ssh2.packets.TypesReader;
e1c445af8e46 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
19 import ch.ethz.ssh2.packets.TypesWriter;
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
20
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 * RSASHA1Verify.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 *
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
25 * @author Christian Plattner, plattner@trilead.com
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
26 * @version $Id: RSASHA1Verify.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 public class RSASHA1Verify {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 private static final Logger log = Logger.getLogger(RSASHA1Verify.class);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 public static RSAPublicKey decodeSSHRSAPublicKey(byte[] key) throws IOException {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 TypesReader tr = new TypesReader(key);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 String key_format = tr.readString();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
35 if (key_format.equals("ssh-rsa") == false)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
36 throw new IllegalArgumentException("This is not a ssh-rsa public key");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 BigInteger e = tr.readMPINT();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 BigInteger n = tr.readMPINT();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
41 if (tr.remain() != 0)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
42 throw new IOException("Padding in RSA public key!");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
43
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
44 KeySpec keySpec = new RSAPublicKeySpec(n, e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
45
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
46 try {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
47 KeyFactory kf = KeyFactory.getInstance("RSA");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
48 return (RSAPublicKey) kf.generatePublic(keySpec);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
50 catch (NoSuchAlgorithmException nsae) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
51 IOException ioe = new IOException("No RSA KeyFactory available");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
52 ioe.initCause(nsae);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
53 throw ioe;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
54 }
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
55 catch (InvalidKeySpecException ikse) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
56 IOException ioe = new IOException("No RSA KeyFactory available");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
57 ioe.initCause(ikse);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
58 throw ioe;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
59 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 public static byte[] encodeSSHRSAPublicKey(RSAPublicKey pk) throws IOException {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 TypesWriter tw = new TypesWriter();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 tw.writeString("ssh-rsa");
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
65 tw.writeMPInt(pk.getPublicExponent());
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
66 tw.writeMPInt(pk.getModulus());
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 return tw.getBytes();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
70 public static byte[] decodeSSHRSASignature(byte[] sig) throws IOException {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 TypesReader tr = new TypesReader(sig);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 String sig_format = tr.readString();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
74 if (sig_format.equals("ssh-rsa") == false)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
75 throw new IOException("Peer sent wrong signature format");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
77 /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 * containing s (which is an integer, without lengths or padding, unsigned and in
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
79 * network byte order)." See also below.
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
80 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 byte[] s = tr.readByteString();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
83 if (s.length == 0)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
84 throw new IOException("Error in RSA signature, S is empty.");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
86 if (log.isEnabled()) {
287
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
87 log.info("Decoding ssh-rsa signature string (length: " + s.length + ")");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
90 if (tr.remain() != 0)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
91 throw new IOException("Padding in RSA signature!");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
92
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
93 if (s[0] == 0 && s[1] == 0 && s[2] == 0) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
94 int i = 0;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
95 int j = ((s[i++] << 24) & 0xff000000) | ((s[i++] << 16) & 0x00ff0000)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
96 | ((s[i++] << 8) & 0x0000ff00) | ((s[i++]) & 0x000000ff);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
97 i += j;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
98 j = ((s[i++] << 24) & 0xff000000) | ((s[i++] << 16) & 0x00ff0000)
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
99 | ((s[i++] << 8) & 0x0000ff00) | ((s[i++]) & 0x000000ff);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
100 byte[] tmp = new byte[j];
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
101 System.arraycopy(s, i, tmp, 0, j);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
102 sig = tmp;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
105 return s;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
108 public static byte[] encodeSSHRSASignature(byte[] s) throws IOException {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 TypesWriter tw = new TypesWriter();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 tw.writeString("ssh-rsa");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
112 /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
113 * containing s (which is an integer, without lengths or padding, unsigned and in
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
114 * network byte order)."
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
115 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
117 /* Remove first zero sign byte, if present */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
119 if ((s.length > 1) && (s[0] == 0x00))
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 tw.writeString(s, 1, s.length - 1);
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
121 else
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 tw.writeString(s, 0, s.length);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 return tw.getBytes();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
127 public static byte[] generateSignature(byte[] message, RSAPrivateKey pk) throws IOException {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 try {
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
129 Signature s = Signature.getInstance("SHA1withRSA");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
130 s.initSign(pk);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
131 s.update(message);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
132 return s.sign();
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
134 catch (NoSuchAlgorithmException e) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
135 IOException ex = new IOException();
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
136 ex.initCause(e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
137 throw ex;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
139 catch (InvalidKeyException e) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
140 IOException ex = new IOException();
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
141 ex.initCause(e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
142 throw ex;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
144 catch (SignatureException e) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
145 IOException ex = new IOException();
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
146 ex.initCause(e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
147 throw ex;
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
148 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
151 public static boolean verifySignature(byte[] message, byte[] ds, RSAPublicKey dpk) throws IOException {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152 try {
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
153 Signature s = Signature.getInstance("SHA1withRSA");
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
154 s.initVerify(dpk);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
155 s.update(message);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
156 return s.verify(ds);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
158 catch (NoSuchAlgorithmException e) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
159 IOException ex = new IOException();
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
160 ex.initCause(e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
161 throw ex;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
163 catch (InvalidKeyException e) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
164 IOException ex = new IOException();
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
165 ex.initCause(e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
166 throw ex;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167 }
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
168 catch (SignatureException e) {
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
169 IOException ex = new IOException();
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
170 ex.initCause(e);
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
171 throw ex;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 }