Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Greatrix committed Nov 22, 2015
1 parent fc31ac0 commit 7e24d49
Show file tree
Hide file tree
Showing 152 changed files with 5,908 additions and 7,354 deletions.
46 changes: 46 additions & 0 deletions TLSv12/src/tlsv12/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package tlsv12;

import javax.net.ssl.HttpsURLConnection;

import java.io.IOException;
import java.io.InputStream;

public class Example {

static void fetchPage(HttpsURLConnection conn) {
try {
InputStream in = conn.getInputStream();
int r;
while( (r = in.read()) != -1 ) {
System.out.print((char) r);
}
in.close();
conn.disconnect();
System.out.println();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}


public static void main(String[] args) throws IOException {
// System.setProperty("javax.net.debug", "ssl");

System.out.println("Fetching from Google");
HttpsURLConnection conn = Tls12Context.getConnection("https://www.google.com");
fetchPage(conn);

System.out.println("Fetching from Facebook");
conn = Tls12Context.getConnection("https://www.facebook.com");
fetchPage(conn);

System.out.println("Fetching from Cybersource");
conn = Tls12Context.getConnection("https://www.cybersource.com");
fetchPage(conn);

System.out.println("Fetching from Harte Hanks");
conn = Tls12Context.getConnection("https://www.hartehanks.com");
fetchPage(conn);
}

}
29 changes: 0 additions & 29 deletions TLSv12/src/tlsv12/TheBigMainApplication.java

This file was deleted.

54 changes: 54 additions & 0 deletions TLSv12/src/tlsv12/Tls12Context.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
package tlsv12;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;

import java.io.IOException;
import java.net.URL;
import java.security.KeyManagementException;

public class Tls12Context extends SSLContext {
/** A default instance of this context */
public static final Tls12Context INSTANCE;

/** A default socket factory using the default instance */
public static final SSLSocketFactory SOCKET_FACTORY;

static {
Tls12Context c = new Tls12Context();
try {
c.init(null, null, null);
} catch (KeyManagementException e) {
throw new Error("Default key manager failed", e);
}
INSTANCE = c;
SOCKET_FACTORY = c.getSocketFactory();
}


/**
* Open an HTTPS connection to the specified URL.
*
* @param url
* the URL to connect to
* @return a connection, or null if the URL is not HTTPS
* @throws IOException
*/
public static HttpsURLConnection getConnection(String url) throws IOException {
if( url == null ) return null;
return getConnection(new URL(url));
}


/**
* Open an HTTPS connection to the specified URL.
*
* @param url
* the URL to connect to
* @return a connection, or null if the URL is not HTTPS
* @throws IOException
*/
public static HttpsURLConnection getConnection(URL url) throws IOException {
if( url == null ) return null;
if( !"https".equals(url.getProtocol()) ) return null;
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(SOCKET_FACTORY);
return conn;
}


public Tls12Context() {
super(new SSLContextImpl.TLS12Context(), new Tls12Provider(), "TLSv1.2");
Expand Down
8 changes: 3 additions & 5 deletions TLSv12/src/tlsv12/asn1/ASN1ApplicationSpecificParser.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package tlsv12.asn1;


/**
* Interface to parse ASN.1 application specific objects.
*/
public interface ASN1ApplicationSpecificParser
extends ASN1Encodable, InMemoryRepresentable
{

public interface ASN1ApplicationSpecificParser extends ASN1Encodable,
InMemoryRepresentable {

}
26 changes: 15 additions & 11 deletions TLSv12/src/tlsv12/asn1/ASN1Choice.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@
* pattern which takes a tag object and the tagging mode used.
* <p>
* <hr>
* <p><b>X.690</b></p>
* <p><b>8: Basic encoding rules</b></p>
* <p><b>8.13 Encoding of a choice value </b></p>
* <p>
* The encoding of a choice value shall be the same as the encoding of a value of the chosen type.
* <blockquote>
* NOTE 1 &mdash; The encoding may be primitive or constructed depending on the chosen type.
* <b>X.690</b>
* </p>
* <p>
* <b>8: Basic encoding rules</b>
* </p>
* <p>
* <b>8.13 Encoding of a choice value </b>
* </p>
* <p>
* The encoding of a choice value shall be the same as the encoding of a value
* of the chosen type. <blockquote> NOTE 1 &mdash; The encoding may be primitive
* or constructed depending on the chosen type.
* <p>
* NOTE 2 &mdash; The tag used in the identifier octets is the tag of the chosen type,
* as specified in the ASN.1 definition of the choice type.
* </blockquote>
* NOTE 2 &mdash; The tag used in the identifier octets is the tag of the chosen
* type, as specified in the ASN.1 definition of the choice type. </blockquote>
* </p>
*/
public interface ASN1Choice
{
public interface ASN1Choice {
// marker interface
}
4 changes: 2 additions & 2 deletions TLSv12/src/tlsv12/asn1/ASN1Encodable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/**
* Basic interface to produce serialisers for ASN.1 encodings.
*/
public interface ASN1Encodable
{
public interface ASN1Encodable {
/**
* Return an object, possibly constructed, of ASN.1 primitives
*
* @return an ASN.1 primitive.
*/
ASN1Primitive toASN1Primitive();
Expand Down
28 changes: 13 additions & 15 deletions TLSv12/src/tlsv12/asn1/ASN1EncodableVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,45 @@
/**
* Mutable class for building ASN.1 constructed objects.
*/
public class ASN1EncodableVector
{
public class ASN1EncodableVector {
Vector v = new Vector();


/**
* Base constructor.
*/
public ASN1EncodableVector()
{
}
public ASN1EncodableVector() {}


/**
* Add an encodable to the vector.
*
* @param obj the encodable to add.
* @param obj
* the encodable to add.
*/
public void add(ASN1Encodable obj)
{
public void add(ASN1Encodable obj) {
v.addElement(obj);
}



/**
* Return the object at position i in this vector.
*
* @param i the index of the object of interest.
* @param i
* the index of the object of interest.
* @return the object at position i.
*/
public ASN1Encodable get(int i)
{
return (ASN1Encodable)v.elementAt(i);
public ASN1Encodable get(int i) {
return (ASN1Encodable) v.elementAt(i);
}


/**
* Return the size of the vector.
*
* @return the object count in the vector.
*/
public int size()
{
public int size() {
return v.size();
}
}
1 change: 0 additions & 1 deletion TLSv12/src/tlsv12/asn1/ASN1Enumerated.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tlsv12.util.Arrays;

import java.io.IOException;
import java.math.BigInteger;

/**
* Class representing the ASN.1 ENUMERATED type.
Expand Down
16 changes: 7 additions & 9 deletions TLSv12/src/tlsv12/asn1/ASN1Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

import java.io.IOException;

public class ASN1Exception
extends IOException
{
public class ASN1Exception extends IOException {
private Throwable cause;

ASN1Exception(String message)
{

ASN1Exception(String message) {
super(message);
}

ASN1Exception(String message, Throwable cause)
{

ASN1Exception(String message, Throwable cause) {
super(message);
this.cause = cause;
}

public Throwable getCause()
{

public Throwable getCause() {
return cause;
}
}
Loading

0 comments on commit 7e24d49

Please sign in to comment.