Author: mturk
Date: Sat Sep 24 14:53:50 2011
New Revision: 1175173
URL: http://svn.apache.org/viewvc?rev=1175173&view=rev
Log:
Add store files
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCAStore.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCRLStore.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCannotDecryptException.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLStore.java
(with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h
commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c
commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c
commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c
commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
Sat Sep 24 14:53:50 2011
@@ -19,4 +19,6 @@ fips.ENOTIMPL=FIPS was not available at
password.PROMPT=Some of your private key files are encrypted for security
reasons.\
\nIn order to read them you have to provide the pass phrases.\
\nEnter password :
-sslctx.ENOCRLLOC=At least one of CARevocationFile or CARevocationPath must be
configured.
+sslctx.ENOCRLLOC=At least one of CARevocationFile or CARevocationPath must be
configured
+store.ENOTREG=File '{0}' does not exist or is empty
+store.ENOTDIR=Path '{0}' is not directory
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCAStore.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCAStore.java?rev=1175173&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCAStore.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCAStore.java
Sat Sep 24 14:53:50 2011
@@ -0,0 +1,35 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.ssl;
+
+/**
+ * Represents the SSL Certificate Authority (CA).
+ */
+public class SSLCAStore extends SSLStore
+{
+
+ public SSLCAStore()
+ {
+ }
+
+ @Override
+ public final void dispose()
+ {
+ // Nothing since we don't have
+ // native object wrapped.
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCAStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCRLStore.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCRLStore.java?rev=1175173&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCRLStore.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCRLStore.java
Sat Sep 24 14:53:50 2011
@@ -0,0 +1,35 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.ssl;
+
+/**
+ * Represents the SSL Certificate Revocation Lists (CRL) store.
+ */
+public class SSLCRLStore extends SSLStore
+{
+
+ public SSLCRLStore()
+ {
+ }
+
+ @Override
+ public final void dispose()
+ {
+ // Nothing since we don't have
+ // native object wrapped.
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCRLStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCannotDecryptException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCannotDecryptException.java?rev=1175173&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCannotDecryptException.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCannotDecryptException.java
Sat Sep 24 14:53:50 2011
@@ -0,0 +1,40 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.ssl;
+import org.apache.commons.runtime.InvalidDataException;
+
+/**
+ * Reports a bad SSL decryption attempt.
+ * Normally, this indicates invalid passphrase provided to
+ * the key or certificate.
+ *
+ * @since Runtime 1.0
+ */
+
+public class SSLCannotDecryptException extends InvalidDataException
+{
+
+ public SSLCannotDecryptException()
+ {
+ super();
+ }
+
+ public SSLCannotDecryptException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCannotDecryptException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
Sat Sep 24 14:53:50 2011
@@ -31,9 +31,9 @@ public final class SSLCertificate extend
private SSLCertificateFormat format;
private static native long load0(String file, String desc, int format,
long pcb)
- throws SSLInvalidCertificateException;
+ throws SSLCannotDecryptException, SSLInvalidCertificateException;
private static native long load1(String file, int format, String password)
- throws SSLInvalidCertificateException;
+ throws SSLCannotDecryptException, SSLInvalidCertificateException;
private static native void free0(long cert);
/**
@@ -55,7 +55,9 @@ public final class SSLCertificate extend
}
public synchronized void load(String file, SSLCertificateFormat format,
PasswordCallback cb)
- throws IllegalStateException, SSLInvalidCertificateException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidCertificateException
{
if (super.pointer != 0L) {
// Already loaded
@@ -66,7 +68,9 @@ public final class SSLCertificate extend
}
public synchronized void load(String file, SSLCertificateFormat format)
- throws IllegalStateException, SSLInvalidCertificateException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidCertificateException
{
if (super.pointer != 0L) {
// Already loaded
@@ -77,7 +81,9 @@ public final class SSLCertificate extend
}
public synchronized void load(String file, SSLCertificateFormat format,
String password)
- throws IllegalStateException, SSLInvalidCertificateException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidCertificateException
{
if (super.pointer != 0L) {
// Already loaded
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
Sat Sep 24 14:53:50 2011
@@ -25,7 +25,6 @@ import org.apache.commons.runtime.Status
import org.apache.commons.runtime.SystemException;
import java.io.File;
-import java.nio.ByteBuffer;
/**
* Contains the context structure for global default values for
@@ -41,7 +40,6 @@ public final class SSLContext extends Na
private final long pointer = 0L;
private SSLKey[] keys;
private SSLCertificate[] cert;
- private boolean has_crlset = false;
private static native long new0(int protocol, int mode)
throws OperationNotImplementedException;
@@ -53,11 +51,11 @@ public final class SSLContext extends Na
private static native void setpasscb0(long ctx, long cb);
private static native void setvmode0(long ctx, int mode, int depth);
- private static final int SET_CTX_CA_CERT_FILE = 1;
- private static final int SET_CTX_CA_CERT_PATH = 2;
- private static final int SET_CTX_CRL_FILE = 3;
- private static final int SET_CTX_CRL_PATH = 4;
- private static final int SET_CTX_CIPHER_SUITE = 5;
+ private static final int SET_CTX_CA_CERT_FILE = 1;
+ private static final int SET_CTX_CA_CERT_PATH = 2;
+ private static final int SET_CTX_CRL_FILE = 3;
+ private static final int SET_CTX_CRL_PATH = 4;
+ private static final int SET_CTX_CIPHER_SUITE = 5;
private static native void setstropt0(long ctx, int opt, String val);
@@ -128,15 +126,25 @@ public final class SSLContext extends Na
* which can be used e.g. for descriptions of the certificates.
*
* @param path PEM format file of CA's.
+ *
+ * @throws InvalidArgumentException if the file does not exist or is empty.
+ * @throws ObjectNotInitializedException if context is invalid
+ * @throws SecurityException if security manager denies access
+ * to the file
*/
public synchronized void setCACertificateFile(String path)
- throws SSLException, ObjectNotInitializedException
+ throws InvalidArgumentException,
+ ObjectNotInitializedException,
+ SecurityException
{
if (super.pointer == 0L)
throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
- setstropt0(super.pointer, SET_CTX_CA_CERT_FILE, path);
+ File file = new File(path);
+ if (!file.isFile() || file.length() == 0L)
+ throw new InvalidArgumentException(Local.sm.get("file.ENOTREG",
path));
+ setstropt0(super.pointer, SET_CTX_CA_CERT_FILE, file.getPath());
}
/**
@@ -158,17 +166,26 @@ public final class SSLContext extends Na
* the verification of a peer certificate.
* </p>
* @param path PEM format directory of CA's.
+ *
+ * @throws InvalidArgumentException if the path does not exist or is not
+ * an directory.
* @throws ObjectNotInitializedException if context is invalid
- * @throws SSLException if path cannot be set
+ * @throws SecurityException if security manager denies access
+ * to the path
*/
public synchronized void setCACertificatePath(String path)
- throws SSLException, ObjectNotInitializedException
+ throws InvalidArgumentException,
+ ObjectNotInitializedException,
+ SecurityException
{
if (super.pointer == 0L)
throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
- setstropt0(super.pointer, SET_CTX_CA_CERT_PATH, path);
+ File file = new File(path);
+ if (!file.isDirectory())
+ throw new InvalidArgumentException(Local.sm.get("file.ENOTDIR",
path));
+ setstropt0(super.pointer, SET_CTX_CA_CERT_PATH, file.getPath());
}
/**
@@ -185,13 +202,18 @@ public final class SSLContext extends Na
* @throws SSLException if path cannot be set.
*/
public synchronized void setCARevocationFile(String path)
- throws SSLException, ObjectNotInitializedException
+ throws InvalidArgumentException,
+ ObjectNotInitializedException,
+ SecurityException
{
if (super.pointer == 0L)
throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
- setstropt0(super.pointer, SET_CTX_CRL_FILE, path);
+ File file = new File(path);
+ if (!file.isFile() || file.length() == 0L)
+ throw new InvalidArgumentException(Local.sm.get("file.ENOTREG",
path));
+ setstropt0(super.pointer, SET_CTX_CRL_FILE, file.getPath());
}
/**
@@ -205,13 +227,18 @@ public final class SSLContext extends Na
* @throws SSLException if path cannot be set.
*/
public synchronized void setCARevocationPath(String path)
- throws SSLException, ObjectNotInitializedException
+ throws InvalidArgumentException,
+ ObjectNotInitializedException,
+ SecurityException
{
if (super.pointer == 0L)
throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
- setstropt0(super.pointer, SET_CTX_CRL_PATH, path);
+ File file = new File(path);
+ if (!file.isDirectory())
+ throw new InvalidArgumentException(Local.sm.get("file.ENOTDIR",
path));
+ setstropt0(super.pointer, SET_CTX_CRL_PATH, file.getPath());
}
/**
@@ -230,8 +257,6 @@ public final class SSLContext extends Na
{
if (super.pointer == 0L)
throw new ObjectNotInitializedException();
- if (!has_crlset)
- throw new IllegalStateException(Local.sm.get("sslctx.ENOCRLLOC"));
setcrlcheck0(super.pointer, mode.valueOf());
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
Sat Sep 24 14:53:50 2011
@@ -30,9 +30,9 @@ public final class SSLKey extends Native
private final String desc;
private SSLKeyFormat format;
private static native long load0(String file, String desc, int format,
long pcb)
- throws SSLInvalidKeyException;
+ throws SSLCannotDecryptException, SSLInvalidKeyException;
private static native long load1(String file, int format, String password)
- throws SSLInvalidKeyException;
+ throws SSLCannotDecryptException, SSLInvalidKeyException;
private static native void free0(long key);
/**
@@ -54,7 +54,9 @@ public final class SSLKey extends Native
}
public synchronized void load(String file, SSLKeyFormat format,
PasswordCallback cb)
- throws IllegalStateException, SSLInvalidKeyException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidKeyException
{
if (super.pointer != 0L) {
// Already loaded
@@ -65,7 +67,9 @@ public final class SSLKey extends Native
}
public synchronized void load(String file, SSLKeyFormat format, String
password)
- throws IllegalStateException, SSLInvalidKeyException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidKeyException
{
if (super.pointer != 0L) {
// Already loaded
@@ -76,7 +80,9 @@ public final class SSLKey extends Native
}
public synchronized void load(String file, SSLKeyFormat format)
- throws IllegalStateException, SSLInvalidKeyException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidKeyException
{
if (super.pointer != 0L) {
// Already loaded
@@ -87,7 +93,9 @@ public final class SSLKey extends Native
}
public void load(String file)
- throws IllegalStateException, SSLInvalidKeyException
+ throws IllegalStateException,
+ SSLCannotDecryptException,
+ SSLInvalidKeyException
{
load(file, SSLKeyFormat.PEM);
}
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLStore.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLStore.java?rev=1175173&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLStore.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLStore.java
Sat Sep 24 14:53:50 2011
@@ -0,0 +1,97 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.ssl;
+
+import org.apache.commons.runtime.Disposable;
+import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.InvalidDataException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Abstract OpenSSL store.
+ */
+public abstract class SSLStore implements Disposable
+{
+ private File file;
+ private File path;
+
+ protected SSLStore()
+ {
+ file = null;
+ path = null;
+ }
+
+ /**
+ * Set this store file.
+ *
+ * @throws InvalidArgumentException if the file does not exist or is empty.
+ * @throws SecurityException if security manager denies access
+ * to the file
+ */
+ public synchronized void setFile(String file)
+ throws InvalidArgumentException,
+ SecurityException
+ {
+ if (file == null)
+ throw new NullPointerException();
+ this.file = new File(file);
+ if (!this.file.isFile() || this.file.length() == 0L)
+ throw new InvalidArgumentException(Local.sm.get("store.ENOTREG",
path));
+ }
+
+ /**
+ * Set this store directory path.
+ *
+ * @throws InvalidArgumentException if the path does not exist or is not
+ * an directory.
+ * @throws SecurityException if security manager denies access
+ * to the file
+ */
+ public synchronized void setPath(String path)
+ throws InvalidArgumentException,
+ SecurityException
+ {
+ if (path == null)
+ throw new NullPointerException();
+ this.path = new File(path);
+ if (!this.path.isDirectory())
+ throw new InvalidArgumentException(Local.sm.get("store.ENOTDIR",
path));
+
+ }
+
+ /**
+ * Get this store file path.
+ *
+ * @return file path or {@code null} if it wasn't set.
+ */
+ public String getFile()
+ {
+ return file == null ? null : file.getPath();
+ }
+
+ /**
+ * Get this store directory path.
+ *
+ * @return directory path or {@code null} if it wasn't set.
+ */
+ public String getPath()
+ {
+ return path == null ? null : path.getPath();
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java
Sat Sep 24 14:53:50 2011
@@ -246,13 +246,25 @@ public final class Ascii
}
public static void tolower(byte[] arr, int srcPos, int len)
+ throws NullPointerException,
+ IndexOutOfBoundsException
{
+ if (arr == null)
+ throw new NullPointerException();
+ if (len < 0 || srcPos < 0 || srcPos + len > arr.length)
+ throw new IndexOutOfBoundsException();
for (int i = srcPos; i < len; i++)
arr[i] = (byte)ccs_clower[(int)arr[i] & 0xff];
}
public static void toupper(byte[] arr, int srcPos, int len)
+ throws NullPointerException,
+ IndexOutOfBoundsException
{
+ if (arr == null)
+ throw new NullPointerException();
+ if (len < 0 || srcPos < 0 || srcPos + len > arr.length)
+ throw new IndexOutOfBoundsException();
for (int i = srcPos; i < len; i++)
arr[i] = (byte)ccs_cupper[(int)arr[i] & 0xff];
}
@@ -271,19 +283,31 @@ public final class Ascii
* @param base number base to use {@code (2 - 36)} or {@code 0} for guess.
*
* @return integer value of the {@code Ascii} string pointed by {@code
arr}.
+ *
+ * @throws NullPointerException if {@code arr} is {@code null}.
+ * @throws IndexOutOfBoundsException if conversion would cause access
+ * outside array bounds.
+ * @throws NumberFormatException if input data cannot be converted.
*/
public static int atoi(byte[] arr, int srcPos, int len, int base)
+ throws NullPointerException,
+ IndexOutOfBoundsException,
+ NumberFormatException
{
- int acc;
- int val;
+ int acc = 0;
+ int val = 0;
+ int any = 0;
int neg;
- int any;
int i = srcPos;
int c;
+ if (arr == null)
+ throw new NullPointerException();
+ if (len < 0 || srcPos < 0 || srcPos + len > arr.length)
+ throw new IndexOutOfBoundsException();
+ if (len == 0)
+ throw new NumberFormatException();
// Skip leading spaces
- if (len < 1)
- return 0;
do {
c = arr[i++];
} while (isspace(c) && i < len);
@@ -294,16 +318,17 @@ public final class Ascii
c = arr[i++];
else {
// EINVAL
- return 0;
+ throw new NumberFormatException();
}
- } else {
+ }
+ else {
neg = 0;
if (c == '+') {
if (i < len)
c = arr[i++];
else {
// EINVAL
- return 0;
+ throw new NumberFormatException();
}
}
}
@@ -316,17 +341,15 @@ public final class Ascii
}
else {
// EINVAL
- return 0;
+ throw new NumberFormatException();
}
}
if (base == 0)
base = c == '0' ? 8 : 10;
- acc = any = 0;
if (base < 2 || base > 36) {
// EINVAL
- return acc;
+ throw new NumberFormatException();
}
- val = 0;
while (i <= len) {
if (c >= '0' && c <= '9')
c -= '0';
@@ -339,12 +362,13 @@ public final class Ascii
if (c >= base)
break;
val *= base;
- if ((any < 0) || /* already noted an over/under flow - short
circuit */
- (neg != 0 && (val > acc || (val -= c) > acc)) || /*
underflow */
- (neg == 0 && (val < acc || (val += c) < acc))) { /*
overflow */
- any = -1; /* once noted, over/underflows never go away */
+ if ((any < 0) || // already noted an over/under flow - short
circuit
+ (neg != 0 && (val > acc || (val -= c) > acc)) || //
underflow
+ (neg == 0 && (val < acc || (val += c) < acc))) { // overflow
+ any = -1; // once noted, over/underflows never go away
break;
- } else {
+ }
+ else {
acc = val;
any = 1;
}
@@ -355,8 +379,10 @@ public final class Ascii
if (any < 0) {
acc = neg == 0 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
- } else if (any == 0) {
+ }
+ else if (any == 0) {
// EINVAL
+ throw new NumberFormatException();
}
return acc;
}
@@ -375,19 +401,31 @@ public final class Ascii
* @param base number base to use {@code (2 - 36)} or {@code 0} for guess.
*
* @return long value of the {@code Ascii} string pointed by {@code arr}.
+ *
+ * @throws NullPointerException if {@code arr} is {@code null}.
+ * @throws IndexOutOfBoundsException if conversion would cause access
+ * outside array bounds.
+ * @throws NumberFormatException if input data cannot be converted.
*/
public static long atol(byte[] arr, int srcPos, int len, int base)
+ throws NullPointerException,
+ IndexOutOfBoundsException,
+ NumberFormatException
{
- long acc;
- long val;
+ long acc = 0L;
+ long val = 0L;
+ int any = 0;
int neg;
- int any;
int i = srcPos;
int c;
+ if (arr == null)
+ throw new NullPointerException();
+ if (len < 0 || srcPos < 0 || srcPos + len > arr.length)
+ throw new IndexOutOfBoundsException();
+ if (len == 0)
+ throw new NumberFormatException();
// Skip leading spaces
- if (len < 1)
- return 0;
do {
c = arr[i++];
} while (isspace(c) && i < len);
@@ -398,16 +436,17 @@ public final class Ascii
c = arr[i++];
else {
// EINVAL
- return 0;
+ throw new NumberFormatException();
}
- } else {
+ }
+ else {
neg = 0;
if (c == '+') {
if (i < len)
c = arr[i++];
else {
// EINVAL
- return 0;
+ throw new NumberFormatException();
}
}
}
@@ -420,17 +459,15 @@ public final class Ascii
}
else {
// EINVAL
- return 0;
+ throw new NumberFormatException();
}
}
if (base == 0)
base = c == '0' ? 8 : 10;
- acc = any = 0;
if (base < 2 || base > 36) {
// EINVAL
- return acc;
+ throw new NumberFormatException();
}
- val = 0;
while (i <= len) {
if (c >= '0' && c <= '9')
c -= '0';
@@ -443,12 +480,13 @@ public final class Ascii
if (c >= base)
break;
val *= base;
- if ((any < 0) || /* already noted an over/under flow - short
circuit */
- (neg != 0 && (val > acc || (val -= c) > acc)) || /*
underflow */
- (neg == 0 && (val < acc || (val += c) < acc))) { /*
overflow */
- any = -1; /* once noted, over/underflows never go away */
+ if ((any < 0) || // already noted an over/under flow - short
circuit
+ (neg != 0 && (val > acc || (val -= c) > acc)) || //
underflow
+ (neg == 0 && (val < acc || (val += c) < acc))) { // overflow
+ any = -1; // once noted, over/underflows never go away
break;
- } else {
+ }
+ else {
acc = val;
any = 1;
}
@@ -458,9 +496,12 @@ public final class Ascii
}
if (any < 0) {
+ // EOVERFLOW
acc = neg == 0 ? Long.MAX_VALUE : Long.MIN_VALUE;
- } else if (any == 0) {
+ }
+ else if (any == 0) {
// EINVAL
+ throw new NumberFormatException();
}
return acc;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Sat Sep
24 14:53:50 2011
@@ -69,6 +69,7 @@ enum {
ACR_EX_ECONNABORTED, /* ConnectionAbortedException */
ACR_EX_ECONNRESET, /* ConnectionResetException */
ACR_EX_ESSL, /* SSLException */
+ ACR_EX_ESSLBADDEC, /* SSLCannotDecryptException */
ACR_EX_ESSLBADCERT, /* SSLInvalidCertificateException */
ACR_EX_ESSLBADKEY, /* SSLInvalidKeyException */
ACR_EX_LEN
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h Sat Sep 24
14:53:50 2011
@@ -323,7 +323,7 @@ typedef struct acr_ssl_srv_t acr_ssl_
typedef struct acr_ssl_ctx_t {
acr_refcount_t refs;
int inited;
- /* acr_ssl_obj_t */
+
SSL_CTX *ctx;
/* Pointer to the context verify store */
X509_STORE *store;
@@ -482,6 +482,7 @@ void ssl_throw_errno(JNI_STDENV,
void ssl_throw_errno_ex(JNI_STDENV, int cls, const char *fmt, ...);
int ssl_obj_release(ssl_obj_t *);
ssl_obj_t *ssl_obj_new(JNI_STDENV, int, void *);
+void *ssl_obj_detach(ssl_obj_t *, int);
#endif
#endif /* _ACR_SSL_H_ */
Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c Sat
Sep 24 14:53:50 2011
@@ -85,8 +85,13 @@ ACR_SSL_EXPORT(jlong, SSLCertificate, lo
WITH_CSTR(desc) {
/* Load key */
cert = load_cert(cb, format, J2S(file), J2S(desc));
- if (cert == 0)
- ssl_throw_errno(env, ACR_EX_ESSLBADCERT);
+ if (cert == 0) {
+ int reason = ERR_GET_REASON(ERR_peek_error());
+ if (reason == EVP_R_BAD_DECRYPT)
+ ssl_throw_errno(env, ACR_EX_ESSLBADDEC);
+ else
+ ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+ }
} DONE_WITH_STR(desc);
} DONE_WITH_STR(file);
@@ -108,8 +113,13 @@ ACR_SSL_EXPORT(jlong, SSLCertificate, lo
}
/* Load key */
cert = load_cert(&cb, format, J2S(file), 0);
- if (cert == 0)
- ssl_throw_errno(env, ACR_EX_ESSLBADCERT);
+ if (cert == 0) {
+ int reason = ERR_GET_REASON(ERR_peek_error());
+ if (reason == EVP_R_BAD_DECRYPT)
+ ssl_throw_errno(env, ACR_EX_ESSLBADDEC);
+ else
+ ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+ }
} DONE_WITH_STR(password);
} DONE_WITH_STR(file);
Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c Sat Sep
24 14:53:50 2011
@@ -456,3 +456,4 @@ ACR_SSL_EXPORT(void, SSLContext, setscac
else
SSL_CTX_sess_set_cache_size(c->ctx, size);
}
+
Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c Sat Sep
24 14:53:50 2011
@@ -86,8 +86,13 @@ ACR_SSL_EXPORT(jlong, SSLKey, load0)(JNI
WITH_CSTR(desc) {
/* Load key */
key = load_key(cb, format, J2S(file), J2S(desc));
- if (key == 0)
- ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+ if (key == 0) {
+ int reason = ERR_GET_REASON(ERR_peek_error());
+ if (reason == EVP_R_BAD_DECRYPT)
+ ssl_throw_errno(env, ACR_EX_ESSLBADDEC);
+ else
+ ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+ }
} DONE_WITH_STR(desc);
} DONE_WITH_STR(file);
@@ -109,8 +114,13 @@ ACR_SSL_EXPORT(jlong, SSLKey, load1)(JNI
}
/* Load key */
key = load_key(&cb, format, J2S(file), 0);
- if (key == 0)
- ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+ if (key == 0) {
+ int reason = ERR_GET_REASON(ERR_peek_error());
+ if (reason == EVP_R_BAD_DECRYPT)
+ ssl_throw_errno(env, ACR_EX_ESSLBADDEC);
+ else
+ ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+ }
} DONE_WITH_STR(password);
} DONE_WITH_STR(file);
Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c Sat
Sep 24 14:53:50 2011
@@ -507,3 +507,16 @@ ssl_obj_t *ssl_obj_new(JNI_STDENV, int t
}
return o;
}
+
+void *ssl_obj_detach(ssl_obj_t *o, int destroy)
+{
+ void *p;
+ if (o == 0)
+ return 0;
+ p = o->u.any;
+ o->u.any = 0;
+ if (destroy)
+ ssl_obj_release(o);
+ return p;
+}
+
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Sep 24
14:53:50 2011
@@ -63,6 +63,8 @@ static struct {
{ 0, ACR_NET_CP "ConnectionAbortedException" }, /*
ECONNABORTED */
{ 0, ACR_NET_CP "ConnectionResetException" }, /*
ECONNRESET */
{ 0, ACR_SSL_CP "SSLException" }, /* ESSL
*/
+ { 0, ACR_SSL_CP "SSLCannotDecryptException" }, /*
ESSLBADDEC */
+ { 0, ACR_SSL_CP "SSLInvalidCertificateException" }, /*
ESSLBADCERT */
{ 0, ACR_SSL_CP "SSLInvalidKeyException" } /*
ESSLBADKEY */
};
Modified:
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java?rev=1175173&r1=1175172&r2=1175173&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
Sat Sep 24 14:53:50 2011
@@ -49,17 +49,26 @@ public class TestOpenSSL extends Assert
}
}
- public class TestPointer extends NativePointer
+ public abstract class AbstractTestPointer extends NativePointer
{
// Hide NativePointer
private final long pointer = 0L;
- public TestPointer()
+ public AbstractTestPointer()
{
super.pointer = 1234L;
}
+ }
+
+ public class TestPointer extends AbstractTestPointer
+ {
+ public TestPointer()
+ {
+ ((NativePointer)this).pointer = 5678L;
+ }
+
public void dispose()
{
- super.pointer = 0L;
+ ((NativePointer)this).pointer = 0L;
}
}
@@ -84,7 +93,7 @@ public class TestOpenSSL extends Assert
public void nativePointer()
{
TestPointer p = new TestPointer();
- assertEquals(((NativePointer)p).pointer, 1234L);
+ assertEquals(((NativePointer)p).pointer, 5678L);
((NativePointer)p).pointer = 0L;
assertEquals(((NativePointer)p).pointer, 0L);
}