• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.email.mail.transport;
18 
19 import android.net.SSLCertificateSocketFactory;
20 
21 import javax.net.ssl.SSLSocketFactory;
22 
23 public class SSLUtils {
24     private static SSLSocketFactory sInsecureFactory;
25     private static SSLSocketFactory sSecureFactory;
26 
27     /**
28      * Returns a {@link SSLSocketFactory}.  Optionally bypass all SSL certificate checks.
29      *
30      * @param insecure if true, bypass all SSL certificate checks
31      */
getSSLSocketFactory(boolean insecure)32     public synchronized static final SSLSocketFactory getSSLSocketFactory(boolean insecure) {
33         if (insecure) {
34             if (sInsecureFactory == null) {
35                 sInsecureFactory = SSLCertificateSocketFactory.getInsecure(0, null);
36             }
37             return sInsecureFactory;
38         } else {
39             if (sSecureFactory == null) {
40                 sSecureFactory = SSLCertificateSocketFactory.getDefault(0, null);
41             }
42             return sSecureFactory;
43         }
44     }
45 }
46