Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.tls;
  
  
  
 public class TlsExtensionsUtils
 {
     public static final Integer EXT_encrypt_then_mac = Integers.valueOf(.);
     public static final Integer EXT_extended_master_secret = Integers.valueOf(.);
     public static final Integer EXT_heartbeat = Integers.valueOf(.);
     public static final Integer EXT_max_fragment_length = Integers.valueOf(.);
     public static final Integer EXT_server_name = Integers.valueOf(.);
     public static final Integer EXT_status_request = Integers.valueOf(.);
     public static final Integer EXT_truncated_hmac = Integers.valueOf(.);
 
     public static Hashtable ensureExtensionsInitialised(Hashtable extensions)
     {
         return extensions == null ? new Hashtable() : extensions;
     }
 
     public static void addEncryptThenMACExtension(Hashtable extensions)
     {
         extensions.put(createEncryptThenMACExtension());
     }
 
     public static void addExtendedMasterSecretExtension(Hashtable extensions)
     {
     }
 
     public static void addHeartbeatExtension(Hashtable extensionsHeartbeatExtension heartbeatExtension)
         throws IOException
     {
         extensions.put(createHeartbeatExtension(heartbeatExtension));
     }
 
     public static void addMaxFragmentLengthExtension(Hashtable extensionsshort maxFragmentLength)
         throws IOException
     {
         extensions.put(createMaxFragmentLengthExtension(maxFragmentLength));
     }
 
     public static void addServerNameExtension(Hashtable extensionsServerNameList serverNameList)
         throws IOException
     {
         extensions.put(createServerNameExtension(serverNameList));
     }
 
     public static void addStatusRequestExtension(Hashtable extensionsCertificateStatusRequest statusRequest)
         throws IOException
     {
         extensions.put(createStatusRequestExtension(statusRequest));
     }
 
     public static void addTruncatedHMacExtension(Hashtable extensions)
     {
         extensions.put(createTruncatedHMacExtension());
     }
 
     public static HeartbeatExtension getHeartbeatExtension(Hashtable extensions)
         throws IOException
     {
         byte[] extensionData = TlsUtils.getExtensionData(extensions);
         return extensionData == null ? null : readHeartbeatExtension(extensionData);
     }
 
     public static short getMaxFragmentLengthExtension(Hashtable extensions)
         throws IOException
     {
         byte[] extensionData = TlsUtils.getExtensionData(extensions);
         return extensionData == null ? -1 : readMaxFragmentLengthExtension(extensionData);
     }
 
     public static ServerNameList getServerNameExtension(Hashtable extensions)
         throws IOException
     {
         byte[] extensionData = TlsUtils.getExtensionData(extensions);
         return extensionData == null ? null : readServerNameExtension(extensionData);
     }
 
     public static CertificateStatusRequest getStatusRequestExtension(Hashtable extensions)
         throws IOException
     {
         byte[] extensionData = TlsUtils.getExtensionData(extensions);
         return extensionData == null ? null : readStatusRequestExtension(extensionData);
     }
 
     public static boolean hasEncryptThenMACExtension(Hashtable extensionsthrows IOException
     {
         byte[] extensionData = TlsUtils.getExtensionData(extensions);
         return extensionData == null ? false : readEncryptThenMACExtension(extensionData);
     }
 
     public static boolean hasExtendedMasterSecretExtension(Hashtable extensionsthrows IOException
     {
        byte[] extensionData = TlsUtils.getExtensionData(extensions);
        return extensionData == null ? false : readExtendedMasterSecretExtension(extensionData);
    }
    public static boolean hasTruncatedHMacExtension(Hashtable extensionsthrows IOException
    {
        byte[] extensionData = TlsUtils.getExtensionData(extensions);
        return extensionData == null ? false : readTruncatedHMacExtension(extensionData);
    }
    public static byte[] createEmptyExtensionData()
    {
        return .;
    }
    public static byte[] createEncryptThenMACExtension()
    {
        return createEmptyExtensionData();
    }
    public static byte[] createExtendedMasterSecretExtension()
    {
        return createEmptyExtensionData();
    }
    public static byte[] createHeartbeatExtension(HeartbeatExtension heartbeatExtension)
        throws IOException
    {
        if (heartbeatExtension == null)
        {
            throw new TlsFatalAlert(.);
        }
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        heartbeatExtension.encode(buf);
        return buf.toByteArray();
    }
    public static byte[] createMaxFragmentLengthExtension(short maxFragmentLength)
        throws IOException
    {
        TlsUtils.checkUint8(maxFragmentLength);
        byte[] extensionData = new byte[1];
        TlsUtils.writeUint8(maxFragmentLengthextensionData, 0);
        return extensionData;
    }
    public static byte[] createServerNameExtension(ServerNameList serverNameList)
        throws IOException
    {
        if (serverNameList == null)
        {
            throw new TlsFatalAlert(.);
        }
        
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        
        serverNameList.encode(buf);
        return buf.toByteArray();
    }
    public static byte[] createStatusRequestExtension(CertificateStatusRequest statusRequest)
        throws IOException
    {
        if (statusRequest == null)
        {
            throw new TlsFatalAlert(.);
        }
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        statusRequest.encode(buf);
        return buf.toByteArray();
    }
    public static byte[] createTruncatedHMacExtension()
    {
        return createEmptyExtensionData();
    }
    private static boolean readEmptyExtensionData(byte[] extensionDatathrows IOException
    {
        if (extensionData == null)
        {
            throw new IllegalArgumentException("'extensionData' cannot be null");
        }
        if (extensionData.length != 0)
        {
            throw new TlsFatalAlert(.);
        }
        return true;
    }
    public static boolean readEncryptThenMACExtension(byte[] extensionDatathrows IOException
    {
        return readEmptyExtensionData(extensionData);
    }
    public static boolean readExtendedMasterSecretExtension(byte[] extensionDatathrows IOException
    {
        return readEmptyExtensionData(extensionData);
    }
    public static HeartbeatExtension readHeartbeatExtension(byte[] extensionData)
        throws IOException
    {
        if (extensionData == null)
        {
            throw new IllegalArgumentException("'extensionData' cannot be null");
        }
        ByteArrayInputStream buf = new ByteArrayInputStream(extensionData);
        HeartbeatExtension heartbeatExtension = HeartbeatExtension.parse(buf);
        TlsProtocol.assertEmpty(buf);
        return heartbeatExtension;
    }
    public static short readMaxFragmentLengthExtension(byte[] extensionData)
        throws IOException
    {
        if (extensionData == null)
        {
            throw new IllegalArgumentException("'extensionData' cannot be null");
        }
        if (extensionData.length != 1)
        {
            throw new TlsFatalAlert(.);
        }
        return TlsUtils.readUint8(extensionData, 0);
    }
    public static ServerNameList readServerNameExtension(byte[] extensionData)
        throws IOException
    {
        if (extensionData == null)
        {
            throw new IllegalArgumentException("'extensionData' cannot be null");
        }
        ByteArrayInputStream buf = new ByteArrayInputStream(extensionData);
        ServerNameList serverNameList = ServerNameList.parse(buf);
        TlsProtocol.assertEmpty(buf);
        return serverNameList;
    }
    public static CertificateStatusRequest readStatusRequestExtension(byte[] extensionData)
        throws IOException
    {
        if (extensionData == null)
        {
            throw new IllegalArgumentException("'extensionData' cannot be null");
        }
        ByteArrayInputStream buf = new ByteArrayInputStream(extensionData);
        CertificateStatusRequest statusRequest = CertificateStatusRequest.parse(buf);
        TlsProtocol.assertEmpty(buf);
        return statusRequest;
    }
    public static boolean readTruncatedHMacExtension(byte[] extensionDatathrows IOException
    {
        return readEmptyExtensionData(extensionData);
    }
New to GrepCode? Check out our FAQ X