mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-28 17:07:49 +00:00 
			
		
		
		
	Clean-up at NetworkUtils.java
This commit is contained in:
		
							parent
							
								
									93e08bc215
								
							
						
					
					
						commit
						fcf3bd2769
					
				| @ -57,6 +57,12 @@ public class NetworkUtils { | |||||||
|      |      | ||||||
|     /** Default timeout for establishing a connection */ |     /** Default timeout for establishing a connection */ | ||||||
|     public static final int DEFAULT_CONNECTION_TIMEOUT = 60000; |     public static final int DEFAULT_CONNECTION_TIMEOUT = 60000; | ||||||
|  |      | ||||||
|  |     /** Standard name for protocol TLS version 1.2 in Java Secure Socket Extension (JSSE) API */ | ||||||
|  |     public static final String PROTOCOL_TLSv1_2 = "TLSv1.2"; | ||||||
|  |      | ||||||
|  |     /** Standard name for protocol TLS version 1.0 in JSSE API */ | ||||||
|  |     public static final String PROTOCOL_TLSv1_0 = "TLSv1"; | ||||||
| 
 | 
 | ||||||
|     /** Connection manager for all the OwnCloudClients */ |     /** Connection manager for all the OwnCloudClients */ | ||||||
|     private static MultiThreadedHttpConnectionManager mConnManager = null; |     private static MultiThreadedHttpConnectionManager mConnManager = null; | ||||||
| @ -72,7 +78,9 @@ public class NetworkUtils { | |||||||
|      * Registers or unregisters the proper components for advanced SSL handling. |      * Registers or unregisters the proper components for advanced SSL handling. | ||||||
|      * @throws IOException  |      * @throws IOException  | ||||||
|      */ |      */ | ||||||
|     public static void registerAdvancedSslContext(boolean register, Context context) throws GeneralSecurityException, IOException { |     @SuppressWarnings("deprecation") | ||||||
|  | 	public static void registerAdvancedSslContext(boolean register, Context context)  | ||||||
|  |     		throws GeneralSecurityException, IOException { | ||||||
|         Protocol pr = null; |         Protocol pr = null; | ||||||
|         try { |         try { | ||||||
|             pr = Protocol.getProtocol("https"); |             pr = Protocol.getProtocol("https"); | ||||||
| @ -136,9 +144,11 @@ public class NetworkUtils { | |||||||
|      * @throws KeyStoreException            When the KeyStore instance could not be created. |      * @throws KeyStoreException            When the KeyStore instance could not be created. | ||||||
|      * @throws IOException                  When an existing local trust store could not be loaded. |      * @throws IOException                  When an existing local trust store could not be loaded. | ||||||
|      * @throws NoSuchAlgorithmException     When the existing local trust store was saved with an unsupported algorithm. |      * @throws NoSuchAlgorithmException     When the existing local trust store was saved with an unsupported algorithm. | ||||||
|      * @throws CertificateException         When an exception occurred while loading the certificates from the local trust store. |      * @throws CertificateException         When an exception occurred while loading the certificates from the local  | ||||||
|  |      * 										trust store. | ||||||
|      */ |      */ | ||||||
|     private static KeyStore getKnownServersStore(Context context) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { |     private static KeyStore getKnownServersStore(Context context)  | ||||||
|  |     		throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { | ||||||
|         if (mKnownServersStore == null) { |         if (mKnownServersStore == null) { | ||||||
|             //mKnownServersStore = KeyStore.getInstance("BKS"); |             //mKnownServersStore = KeyStore.getInstance("BKS"); | ||||||
|             mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType()); |             mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||||||
| @ -152,15 +162,17 @@ public class NetworkUtils { | |||||||
|                     in.close(); |                     in.close(); | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); // necessary to initialize an empty KeyStore instance |             	// next is necessary to initialize an empty KeyStore instance | ||||||
|  |             	mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return mKnownServersStore; |         return mKnownServersStore; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|      |      | ||||||
|     public static void addCertToKnownServersStore(Certificate cert, Context context) throws  KeyStoreException, NoSuchAlgorithmException,  |     public static void addCertToKnownServersStore(Certificate cert, Context context)  | ||||||
|                                                                                             CertificateException, IOException { |     		throws  KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { | ||||||
|  |     	 | ||||||
|         KeyStore knownServers = getKnownServersStore(context); |         KeyStore knownServers = getKnownServersStore(context); | ||||||
|         knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert); |         knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert); | ||||||
|         FileOutputStream fos = null; |         FileOutputStream fos = null; | ||||||
| @ -182,7 +194,8 @@ public class NetworkUtils { | |||||||
|         return mConnManager; |         return mConnManager; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { |     public static boolean isCertInKnownServersStore(Certificate cert, Context context)  | ||||||
|  |     		throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { | ||||||
|     	 |     	 | ||||||
|     	KeyStore knownServers = getKnownServersStore(context); |     	KeyStore knownServers = getKnownServersStore(context); | ||||||
|     	Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " " |     	Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " " | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user