Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: net/android/java/src/org/chromium/net/DefaultAndroidKeyStore.java

Issue 1002883002: Fix up if statement curly braces issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.util.Log; 7 import android.util.Log;
8 8
9 import java.lang.reflect.Method; 9 import java.lang.reflect.Method;
10 import java.security.NoSuchAlgorithmException; 10 import java.security.NoSuchAlgorithmException;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } catch (Exception e) { 125 } catch (Exception e) {
126 Log.e(TAG, "Exception while signing message with " + javaKey.getAlgo rithm() 126 Log.e(TAG, "Exception while signing message with " + javaKey.getAlgo rithm()
127 + " private key: " + e); 127 + " private key: " + e);
128 return null; 128 return null;
129 } 129 }
130 } 130 }
131 131
132 @Override 132 @Override
133 public int getPrivateKeyType(AndroidPrivateKey key) { 133 public int getPrivateKeyType(AndroidPrivateKey key) {
134 PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey(); 134 PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
135 if (javaKey instanceof RSAPrivateKey) 135 if (javaKey instanceof RSAPrivateKey) return PrivateKeyType.RSA;
136 return PrivateKeyType.RSA; 136 if (javaKey instanceof DSAPrivateKey) return PrivateKeyType.DSA;
137 if (javaKey instanceof DSAPrivateKey) 137 if (javaKey instanceof ECPrivateKey) {
138 return PrivateKeyType.DSA;
139 if (javaKey instanceof ECPrivateKey)
140 return PrivateKeyType.ECDSA; 138 return PrivateKeyType.ECDSA;
141 else 139 } else {
142 return PrivateKeyType.INVALID; 140 return PrivateKeyType.INVALID;
141 }
143 } 142 }
144 143
145 private Object getOpenSSLKeyForPrivateKey(AndroidPrivateKey key) { 144 private Object getOpenSSLKeyForPrivateKey(AndroidPrivateKey key) {
146 PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey(); 145 PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
147 // Sanity checks 146 // Sanity checks
148 if (javaKey == null) { 147 if (javaKey == null) {
149 Log.e(TAG, "key == null"); 148 Log.e(TAG, "key == null");
150 return null; 149 return null;
151 } 150 }
152 if (!(javaKey instanceof RSAPrivateKey)) { 151 if (!(javaKey instanceof RSAPrivateKey)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return opensslKey; 195 return opensslKey;
197 } catch (Exception e) { 196 } catch (Exception e) {
198 Log.e(TAG, "Exception while trying to retrieve system EVP_PKEY handl e: " + e); 197 Log.e(TAG, "Exception while trying to retrieve system EVP_PKEY handl e: " + e);
199 return null; 198 return null;
200 } 199 }
201 } 200 }
202 201
203 @Override 202 @Override
204 public long getOpenSSLHandleForPrivateKey(AndroidPrivateKey key) { 203 public long getOpenSSLHandleForPrivateKey(AndroidPrivateKey key) {
205 Object opensslKey = getOpenSSLKeyForPrivateKey(key); 204 Object opensslKey = getOpenSSLKeyForPrivateKey(key);
206 if (opensslKey == null) 205 if (opensslKey == null) return 0;
207 return 0;
208 206
209 try { 207 try {
210 // Use reflection to invoke the 'getPkeyContext' method on the 208 // Use reflection to invoke the 'getPkeyContext' method on the
211 // result of the getOpenSSLKey(). This is an 32-bit integer 209 // result of the getOpenSSLKey(). This is an 32-bit integer
212 // which is the address of an EVP_PKEY object. Note that this 210 // which is the address of an EVP_PKEY object. Note that this
213 // method these days returns a 64-bit long, but since this code 211 // method these days returns a 64-bit long, but since this code
214 // path is used for older Android versions, it may still return 212 // path is used for older Android versions, it may still return
215 // a 32-bit int here. To be on the safe side, we cast the return 213 // a 32-bit int here. To be on the safe side, we cast the return
216 // value via Number rather than directly to Integer or Long. 214 // value via Number rather than directly to Integer or Long.
217 Method getPkeyContext; 215 Method getPkeyContext;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 "org.apache.harmony.xnet.provider.jsse.OpenSSLEngine"); 248 "org.apache.harmony.xnet.provider.jsse.OpenSSLEngine");
251 } catch (Exception e) { 249 } catch (Exception e) {
252 // This may happen if the target device has a completely different 250 // This may happen if the target device has a completely different
253 // implementation of the java.security APIs, compared to vanilla 251 // implementation of the java.security APIs, compared to vanilla
254 // Android. Highly unlikely, but still possible. 252 // Android. Highly unlikely, but still possible.
255 Log.e(TAG, "Cannot find system OpenSSLEngine class: " + e); 253 Log.e(TAG, "Cannot find system OpenSSLEngine class: " + e);
256 return null; 254 return null;
257 } 255 }
258 256
259 Object opensslKey = getOpenSSLKeyForPrivateKey(key); 257 Object opensslKey = getOpenSSLKeyForPrivateKey(key);
260 if (opensslKey == null) 258 if (opensslKey == null) return null;
261 return null;
262 259
263 try { 260 try {
264 // Use reflection to invoke the 'getEngine' method on the 261 // Use reflection to invoke the 'getEngine' method on the
265 // result of the getOpenSSLKey(). 262 // result of the getOpenSSLKey().
266 Method getEngine; 263 Method getEngine;
267 try { 264 try {
268 getEngine = opensslKey.getClass().getDeclaredMethod("getEngine") ; 265 getEngine = opensslKey.getClass().getDeclaredMethod("getEngine") ;
269 } catch (Exception e) { 266 } catch (Exception e) {
270 // Bail here too, something really not working as expected. 267 // Bail here too, something really not working as expected.
271 Log.e(TAG, "No getEngine() method on OpenSSLKey member:" + e); 268 Log.e(TAG, "No getEngine() method on OpenSSLKey member:" + e);
(...skipping 22 matching lines...) Expand all
294 Log.e(TAG, "Exception while trying to retrieve OpenSSLEngine object: " + e); 291 Log.e(TAG, "Exception while trying to retrieve OpenSSLEngine object: " + e);
295 return null; 292 return null;
296 } 293 }
297 } 294 }
298 295
299 @Override 296 @Override
300 public void releaseKey(AndroidPrivateKey key) { 297 public void releaseKey(AndroidPrivateKey key) {
301 // no-op for in-process. GC will handle key collection 298 // no-op for in-process. GC will handle key collection
302 } 299 }
303 } 300 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698