Skip to main content
summaryrefslogtreecommitdiffstats
blob: bbc01b92940f9e279863a3896abcaa50b578e8de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - initial API and implementation
 *    Caspar De Groot (No Magic Asia Ltd.) - initial API and implementation
 */
package org.eclipse.net4j.internal.tcp.ssl;

import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.om.OMPlatform;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

/**
 * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
 * @author Caspar De Groot (No Magic Asia Ltd.)
 * @since 4.0
 */
public class SSLProperties
{
  public static final String KEY_PATH = "org.eclipse.net4j.tcp.ssl.key";

  public static final String TRUST_PATH = "org.eclipse.net4j.tcp.ssl.trust";

  public static final String PASS_PHRASE = "org.eclipse.net4j.tcp.ssl.passphrase";

  public static final String HANDSHAKE_TIMEOUT = "org.eclipse.net4j.tcp.ssl.handshake.timeout";

  public static final String HANDSHAKE_WAITTIME = "org.eclipse.net4j.tcp.ssl.handshake.waittime";

  public static final String CHECK_VALIDITY_CERTIFICATE = "check.validity.certificate";

  private Properties localProperties;

  public SSLProperties()
  {
  }

  public void load(String localConfigPath) throws IOException
  {
    // Loading SSL config from local property is optional.
    localProperties = new Properties();

    InputStream in = null;

    try
    {
      in = new URL(localConfigPath).openStream();
      localProperties.load(in);
    }
    catch (IOException ex)
    {
      throw ex;
    }
    catch (Exception ex)
    {
      throw WrappedException.wrap(ex, "SSL config cannot be loaded");
    }
    finally
    {
      IOUtil.close(in);
    }
  }

  public String getKeyPath()
  {
    String keyPath = OMPlatform.INSTANCE.getProperty(KEY_PATH);
    if (keyPath == null && localProperties != null)
    {
      keyPath = localProperties.getProperty(KEY_PATH);
    }

    return keyPath;
  }

  public String getTrustPath()
  {
    String trustPath = OMPlatform.INSTANCE.getProperty(TRUST_PATH);
    if (trustPath == null && localProperties != null)
    {
      trustPath = localProperties.getProperty(TRUST_PATH);
    }

    return trustPath;
  }

  public String getPassPhrase()
  {
    String passPhrase = OMPlatform.INSTANCE.getProperty(PASS_PHRASE);
    if (passPhrase == null && localProperties != null)
    {
      passPhrase = localProperties.getProperty(PASS_PHRASE);
    }

    return passPhrase;
  }

  public String getHandShakeTimeOut()
  {
    String hsTimeOut = OMPlatform.INSTANCE.getProperty(HANDSHAKE_TIMEOUT);
    if (hsTimeOut == null && localProperties != null)
    {
      hsTimeOut = localProperties.getProperty(HANDSHAKE_TIMEOUT);
    }

    return hsTimeOut;
  }

  public String getHandShakeWaitTime()
  {
    String waitTime = OMPlatform.INSTANCE.getProperty(HANDSHAKE_WAITTIME);
    if (waitTime == null && localProperties != null)
    {
      waitTime = localProperties.getProperty(HANDSHAKE_WAITTIME);
    }

    return waitTime;
  }
}

Back to the top