1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48:
49:
52: public abstract class SSLCipherSuite
53: {
54: private static final String SERVICE = "SSLCipherSuite";
55: private final String algorithm;
56: private final byte[] id;
57: private final SSLProtocolVersion version;
58: private Provider provider;
59:
60: protected SSLCipherSuite (final String algorithm, final byte[] id,
61: final SSLProtocolVersion version)
62: {
63: this.algorithm = algorithm;
64: if (id.length != 2)
65: throw new IllegalArgumentException ("cipher suite ID must be two bytes");
66: this.id = (byte[]) id.clone ();
67: this.version = version;
68: }
69:
70: public static final SSLCipherSuite getInstance (SSLProtocolVersion version, byte[] id)
71: throws NoSuchAlgorithmException
72: {
73: return getInstance (version + "-" + ((id[0] & 0xFF) + "/" + (id[1] & 0xFF)));
74: }
75:
76: public static final SSLCipherSuite getInstance (SSLProtocolVersion version,
77: byte[] id, Provider provider)
78: throws NoSuchAlgorithmException
79: {
80: return getInstance (version + "-" + (id[0] & 0xFF) + "/" + (id[1] & 0xFF), provider);
81: }
82:
83: public static final SSLCipherSuite getInstance (String name)
84: throws NoSuchAlgorithmException
85: {
86: Provider[] providers = Security.getProviders ();
87: for (int i = 0; i < providers.length; i++)
88: {
89: try
90: {
91: return getInstance (name, providers[i]);
92: }
93: catch (NoSuchAlgorithmException nsae)
94: {
95:
96: }
97: }
98:
99: throw new NoSuchAlgorithmException (SERVICE + ": " + name);
100: }
101:
102: public static final SSLCipherSuite getInstance (String name, Provider provider)
103: throws NoSuchAlgorithmException
104: {
105: SSLCipherSuite suite = null;
106: try
107: {
108: suite = (SSLCipherSuite) Engine.getInstance (SERVICE, name, provider);
109: suite.provider = provider;
110: }
111: catch (InvocationTargetException ite)
112: {
113:
114: NoSuchAlgorithmException nsae = new NoSuchAlgorithmException (name);
115: nsae.initCause (ite);
116: throw nsae;
117: }
118: return suite;
119: }
120:
121: public final String getAlgorithm ()
122: {
123: return algorithm;
124: }
125:
126: public final byte[] getId ()
127: {
128: return (byte[]) id.clone ();
129: }
130:
131: public final Provider getProvider ()
132: {
133: return provider;
134: }
135:
136: public final SSLProtocolVersion getProtocolVersion ()
137: {
138: return version;
139: }
140:
141: public abstract void encipher (ByteBuffer in, ByteBuffer out);
142: }