com.universaldevices.security.upnp
Class UPnPSecurity

java.lang.Object
  extended by com.universaldevices.security.upnp.UPnPSecurity

public class UPnPSecurity
extends java.lang.Object

This class encapsulates all the necessary methods to conform to UPnP Security standards

Author:
UDArchitect

Field Summary
static java.lang.String BLOCK_CIPHER_MODE
           
static java.lang.String BLOCK_CIPHER_PADDING
           
static int BULK_CIPHER_LENGTH
           
static java.lang.String BULK_CIPHER_NAME
          UPnP Security
static java.lang.String BULK_CIPHER_PARAMETERS
           
 java.lang.String controlURL
          Used for signing UPnP messages; this is the URL to which Services are directed in ISY
static java.lang.String DEFAULT_DEVICE_BULK_ALGORITHM
           
static java.lang.String DEFAULT_DEVICE_HMAC_ALGORITHM
           
static java.lang.String DEFAULT_DEVICE_HMAC_ALGORITHM_JAVA
           
static java.lang.String DEFAULT_DIGEST_ALGORITHM_JAVA
           
static java.lang.String DEFAULT_PUBLIC_KEY_SIGNATURE_METHOD
           
 java.security.PublicKey devRSAPubKey
           
 java.lang.String devSessionId
           
 UPnPBulkCipher encryptionFromDevice
          The bulk cipher used to receive communications from ISY This object is not used
 UPnPBulkCipher encryptionToDevice
          The bulk cipher used to communicate to ISY
 boolean isExpired
           
 java.lang.String lifetimeSequenceBase
          This is used to reduce the replay attacks
static short NO_SECURITY
          ISY is not security enabled
static short NO_SIGNATURE
          No signature/encryption is applied
static java.lang.String RSA_CIPHER_PARAMETERS
           
 java.security.KeyPair rsaKeyPair
           
static short SECURITY_LEVEL_1
          ISY supports clear text userid/pwd authentication but requires all messages to be digitally signed
static short SECURITY_LEVEL_2
          ISY supports bulk key encryption on sensitive messages and also requires all messages to be signed
static short SECURITY_LEVEL_3
          ISY requires RSA/PublicKey cryptography
static short SIGN_WITH_HMAC_KEY
          Signs messages using HMAC
static short SIGN_WITH_PUBLIC_KEY
          Signs messages using Public Key
 UPnPHMAC signatureFromDevice
          HMAC signature to be used to receive communications from ISY
 UPnPHMAC signatureToDevice
          HMAC signature to be used to communicate with ISY
static long START_SEQUENCE_NUMBER
          Internal Library use only
 
Constructor Summary
UPnPSecurity()
          Constructor, default
 
Method Summary
 boolean createSecuritySession(short securityLevel)
          Creates a UPnP Security Session instance based on the given security level
 byte[] decrypt(java.lang.String cipherText, byte[] iv)
          Decrypts a cipher
 java.lang.StringBuffer encrypt(java.lang.StringBuffer plainText)
          Encrypts a plaintext with the bulk key to Device key
 boolean expire()
          Returns true if the security session has expired
 java.lang.StringBuffer getSecuritySessionBody(short securityLevel)
          Sings and encrypts (if necessary) a SOAP body
 boolean refresh()
          Refreshes this UPnP security session based on the new parameters retrieved from ISY.
 boolean setDevicePublicKey(java.lang.String modulus, java.lang.String exponent)
          Updates the devices public key with the information retrieved from the device
 void setFreshness(java.lang.String lifetimeSequenceBase, java.lang.String controlURL)
          Sets the UPnP Security's freshness value
 java.lang.StringBuffer sign(java.lang.StringBuffer body, boolean isPubKeySigned, short securityLevel)
          Signs and encrypts the body with PK or BK
 void updateSession(java.lang.String lifetimeSequenceBase, java.lang.String devSessionId)
          Updates a UPnP Security Session based on the given values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_SIGNATURE

public static final short NO_SIGNATURE
No signature/encryption is applied

See Also:
Constant Field Values

SIGN_WITH_PUBLIC_KEY

public static final short SIGN_WITH_PUBLIC_KEY
Signs messages using Public Key

See Also:
Constant Field Values

SIGN_WITH_HMAC_KEY

public static final short SIGN_WITH_HMAC_KEY
Signs messages using HMAC

See Also:
Constant Field Values

encryptionToDevice

public UPnPBulkCipher encryptionToDevice
The bulk cipher used to communicate to ISY


encryptionFromDevice

public UPnPBulkCipher encryptionFromDevice
The bulk cipher used to receive communications from ISY
This object is not used


signatureToDevice

public UPnPHMAC signatureToDevice
HMAC signature to be used to communicate with ISY


signatureFromDevice

public UPnPHMAC signatureFromDevice
HMAC signature to be used to receive communications from ISY


controlURL

public java.lang.String controlURL
Used for signing UPnP messages; this is the URL to which Services are directed in ISY


lifetimeSequenceBase

public java.lang.String lifetimeSequenceBase
This is used to reduce the replay attacks


rsaKeyPair

public java.security.KeyPair rsaKeyPair

devRSAPubKey

public java.security.PublicKey devRSAPubKey

devSessionId

public java.lang.String devSessionId

isExpired

public boolean isExpired

BULK_CIPHER_NAME

public static final java.lang.String BULK_CIPHER_NAME
UPnP Security

See Also:
Constant Field Values

BLOCK_CIPHER_MODE

public static final java.lang.String BLOCK_CIPHER_MODE
See Also:
Constant Field Values

BLOCK_CIPHER_PADDING

public static final java.lang.String BLOCK_CIPHER_PADDING
See Also:
Constant Field Values

BULK_CIPHER_PARAMETERS

public static final java.lang.String BULK_CIPHER_PARAMETERS
See Also:
Constant Field Values

BULK_CIPHER_LENGTH

public static final int BULK_CIPHER_LENGTH
See Also:
Constant Field Values

RSA_CIPHER_PARAMETERS

public static final java.lang.String RSA_CIPHER_PARAMETERS
See Also:
Constant Field Values

DEFAULT_DEVICE_BULK_ALGORITHM

public static final java.lang.String DEFAULT_DEVICE_BULK_ALGORITHM
See Also:
Constant Field Values

DEFAULT_DEVICE_HMAC_ALGORITHM_JAVA

public static final java.lang.String DEFAULT_DEVICE_HMAC_ALGORITHM_JAVA
See Also:
Constant Field Values

DEFAULT_DIGEST_ALGORITHM_JAVA

public static final java.lang.String DEFAULT_DIGEST_ALGORITHM_JAVA
See Also:
Constant Field Values

DEFAULT_DEVICE_HMAC_ALGORITHM

public static final java.lang.String DEFAULT_DEVICE_HMAC_ALGORITHM
See Also:
Constant Field Values

DEFAULT_PUBLIC_KEY_SIGNATURE_METHOD

public static final java.lang.String DEFAULT_PUBLIC_KEY_SIGNATURE_METHOD
See Also:
Constant Field Values

NO_SECURITY

public static final short NO_SECURITY
ISY is not security enabled

See Also:
Constant Field Values

SECURITY_LEVEL_1

public static final short SECURITY_LEVEL_1
ISY supports clear text userid/pwd authentication but requires all messages to be digitally signed

See Also:
Constant Field Values

SECURITY_LEVEL_2

public static final short SECURITY_LEVEL_2
ISY supports bulk key encryption on sensitive messages and also requires all messages to be signed

See Also:
Constant Field Values

SECURITY_LEVEL_3

public static final short SECURITY_LEVEL_3
ISY requires RSA/PublicKey cryptography

See Also:
Constant Field Values

START_SEQUENCE_NUMBER

public static final long START_SEQUENCE_NUMBER
Internal Library use only

See Also:
Constant Field Values
Constructor Detail

UPnPSecurity

public UPnPSecurity()
Constructor, default

Method Detail

createSecuritySession

public boolean createSecuritySession(short securityLevel)
Creates a UPnP Security Session instance based on the given security level

Parameters:
securityLevel - - the security level
Returns:
- true if successful, false otherwise

refresh

public boolean refresh()
Refreshes this UPnP security session based on the new parameters retrieved from ISY. This method is useful when the client is aborted and restarted.

Returns:
- true if successful, false otherwise

setDevicePublicKey

public boolean setDevicePublicKey(java.lang.String modulus,
                                  java.lang.String exponent)
Updates the devices public key with the information retrieved from the device

Parameters:
modulus - - the modulus
exponent - - the exponent
Returns:
- true, if successful, false otherwise

setFreshness

public void setFreshness(java.lang.String lifetimeSequenceBase,
                         java.lang.String controlURL)
Sets the UPnP Security's freshness value

Parameters:
lifetimeSequenceBase - - the sequence base number
controlURL - - the controlURL

updateSession

public void updateSession(java.lang.String lifetimeSequenceBase,
                          java.lang.String devSessionId)
Updates a UPnP Security Session based on the given values

Parameters:
lifetimeSequenceBase - - the sequence number
devSessionId - - the security session's ID

getSecuritySessionBody

public java.lang.StringBuffer getSecuritySessionBody(short securityLevel)
Sings and encrypts (if necessary) a SOAP body

Based on the security level, signs/encrypts and does what ever is necessary to conform the body of the SOAP message to UPnP Security 1.0

Parameters:
securityLevel - - the security level being reported by ISY
Returns:
- the UPnP Security formatted SOAP body

sign

public java.lang.StringBuffer sign(java.lang.StringBuffer body,
                                   boolean isPubKeySigned,
                                   short securityLevel)
Signs and encrypts the body with PK or BK

Signs the body with either the public key or the Sign key provided in the signKeyToDevice HMAC

Parameters:
body -
isPubKeySigned -
Returns:
xml namespace ""; ""

expire

public boolean expire()
Returns true if the security session has expired

Returns:
- whether or not the security session has expired

encrypt

public java.lang.StringBuffer encrypt(java.lang.StringBuffer plainText)
Encrypts a plaintext with the bulk key to Device key

Parameters:
plainText - - the text to be encrypted
Returns:
the decryptAndExecute

decrypt

public byte[] decrypt(java.lang.String cipherText,
                      byte[] iv)
Decrypts a cipher

Parameters:
cipherText -
iv - - the initial vector
Returns:
- the decrypted cipher