Commit c44896d7 authored by Sunil Kumar's avatar Sunil Kumar
Browse files

Added encryption to backup/restore APIs

parent 00ab6626
......@@ -33,7 +33,8 @@ import com.novell.ldap.asn1.ASN1Integer;
* but all the DS level attributes associated with the objects.
*
* <p>The information available includes such items as modification timestamp,
* revision,data blob consisting of backup data of any eDirectory Object
* revision,data blob consisting of backup data of any eDirectory Object. The API
* support backing of both non-encrypted and encrypted objects
* </p>
*
* <p>To get information about any eDirectory Object, you must
......@@ -49,7 +50,8 @@ import com.novell.ldap.asn1.ASN1Integer;
* requestValue ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp; objectDN&nbsp;&nbsp;&nbsp; LDAPDN<br>
* &nbsp;&nbsp;&nbsp;&nbsp; mts(modification timestamp) INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp; revision&nbsp;&nbsp;&nbsp; INTEGER</p>
* &nbsp;&nbsp;&nbsp;&nbsp; revision&nbsp;&nbsp;&nbsp; INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp; passwd&nbsp;&nbsp;&nbsp; OCTET STRING</p>
*/
public class LDAPBackupRequest extends LDAPExtendedOperation {
......@@ -76,6 +78,9 @@ public class LDAPBackupRequest extends LDAPExtendedOperation {
*
* @param objectDN The DN of the object to be backed up
* <br>
* @param passwd The encrypted password required for the object to
* be backed up
* <br>
* @param stateInfo The state information of the object to backup.
* This parameter is a String which contains combination of modification
* timestamp and revision number of object being backed up. The format
......@@ -87,7 +92,7 @@ public class LDAPBackupRequest extends LDAPExtendedOperation {
* @exception LDAPException A general exception which includes an error
* message and an LDAP error code.
*/
public LDAPBackupRequest(String objectDN, String stateInfo)
public LDAPBackupRequest(String objectDN, byte[] passwd, String stateInfo)
throws LDAPException {
super(BackupRestoreConstants.NLDAP_LDAP_BACKUP_REQUEST, null);
......@@ -100,7 +105,11 @@ public class LDAPBackupRequest extends LDAPExtendedOperation {
if (objectDN == null)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
//If encrypted password has null reference make it null String
if(passwd == null)
passwd = "".getBytes("UTF8");
if (stateInfo == null) {
// If null reference is passed in stateInfo initialize both
// mts and revision
......@@ -138,10 +147,12 @@ public class LDAPBackupRequest extends LDAPExtendedOperation {
ASN1OctetString asn1_objectDN = new ASN1OctetString(objectDN);
ASN1Integer asn1_mts = new ASN1Integer(mts);
ASN1Integer asn1_revision = new ASN1Integer(revision);
ASN1OctetString asn1_passwd = new ASN1OctetString(passwd);
asn1_objectDN.encode(encoder, encodedData);
asn1_mts.encode(encoder, encodedData);
asn1_revision.encode(encoder, encodedData);
asn1_passwd.encode(encoder, encodedData);
// set the value of operation specific data
setValue(encodedData.toByteArray());
......
......@@ -40,25 +40,63 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
private int bufferLength; //Represents the length of backup data
private String stateInfo; //Represent the state Information of data
/*
* The String representing the array of chunk sizes and data returned from server.
* The String representing the number of chunks and each elements in chunk
* array as returned by server.
* Data from server is parsed as follows before sending to any Application::
* no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)sizeOf(chunkn);returnedBuffer
* no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)sizeOf(chunkn)
* where
* no_of_chunks => Represents the number of chunks of data returned from server
* sizeOf(chunkn) => Represents the size of data in chunkn
* returnedBuffer => Represents the actual data of returned eDirectoty Object
*/
private String parsedString;
private String chunkSizesString;
/*
* Actual data of returned eDirectoty Object in byte[]
*/
private byte[] returnedBuffer;
/**
* Constructs an object from the responseValue which contains the backup data.
* <p>The constructor parses the responseValue which has the following
* format:<br>
* responseValue ::=<br>
* <p>databufferLength ::= INTEGER <br>
* mts(modification time stamp) ::= INTEGER<br>
* revision ::= INTEGER<br>
* returnedBuffer ::= OCTET STRING<br>
* dataChunkSizes ::= <br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;
* SEQUENCE{<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* noOfChunks INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* SET of [<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* SEQUENCE of {eachChunksize INTEGER}]<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* }</p>
*
* @exception IOException The responseValue could not be decoded.
*/
public LDAPBackupResponse(RfcLDAPMessage rfcMessage) throws IOException {
//Call the super constructor
super(rfcMessage);
int modificationTime = 0; // Modifaction time stamp of the Object
int modificationTime = 0; // Modifaction timestamp of the Object
int revision = 0; // Revision number of the Object
String returnedBuffer = null; //Actual data of returned eDirectoty Object
int chunksSize = 0;
int[] chunks = null; //Holds size of each chunks returned from server
......@@ -113,7 +151,8 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
.decode(currentPtr);
if (asn1_returnedBuffer == null)
throw new IOException("Decoding error");
returnedBuffer = asn1_returnedBuffer.stringValue();
returnedBuffer = asn1_returnedBuffer.byteValue();
/*
* Parse chunks array
......@@ -136,7 +175,6 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
chunks = new int[chunksSize];
ASN1Set asn1_chunksSet = (ASN1Set)asn1_chunksSeq.get(1);
//Iterate through asn1_chunksSet and put each size into chunks array
for (int index = 0; index < chunksSize; index++) {
ASN1Sequence asn1_eachSeq = (ASN1Sequence)asn1_chunksSet.get(index);
......@@ -148,19 +186,21 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
StringBuffer tempBuffer = new StringBuffer();
tempBuffer.append(chunksSize);
tempBuffer.append(";");
for (int i = 0; i < chunksSize; i++) {
int i = 0;
for (; i < (chunksSize - 1); i++) {
tempBuffer.append(chunks[i]);
tempBuffer.append(";");
}
tempBuffer.append(returnedBuffer);
tempBuffer.append(chunks[i]);
//Assign tempBuffer to parsedString to be returned to Application
this.parsedString = tempBuffer.toString();
this.chunkSizesString = tempBuffer.toString();
} else {
//Intialize all these if getResultCode() != LDAPException.SUCCESS
this.bufferLength = 0;
this.stateInfo = null;
this.parsedString = null;
this.chunkSizesString = null;
this.returnedBuffer = null;
}
}
......@@ -189,17 +229,24 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
/**
* Returns the data in String as::<br>
* no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)sizeOf(chunkn);returnedBuffer<br>
* no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)sizeOf(chunkn)<br>
* where<br>
* no_of_chunks => Represents the number of chunks of data returned from server<br>
* sizeOf(chunkn) => Represents the size of data in chunkn<br>
* returnedBuffer => Represents the actual data of returned eDirectoty Object
*
* @return parsedString as String.
*
* @return chunkSizesString as String.
*/
public String getParsedString() {
return parsedString;
public String getChunkSizesString() {
return chunkSizesString;
}
/**
* Returns the data buffer as byte[]
*
* @return returnedBuffer as byte[].
*/
public byte[] getReturnedBuffer() {
return returnedBuffer;
}
}
\ No newline at end of file
......@@ -33,8 +33,9 @@ import com.novell.ldap.resources.ExceptionMessages;
* restore of eDirectory objects.
*
* <p>The information need for restore includes such items as object DN,
* data buffer length, string containing the chunks sizes and data blob
* consisting of atual backup data returned from server.
* data buffer length, string containing the number of chunks and each chunk
* elements representing the size of each chunk, data blob in byte[]. The API
* support restoring of both non-encrypted and encrypted objects.
* </p>
*
* <p>To send this request to eDirectory, you must
......@@ -48,6 +49,10 @@ import com.novell.ldap.resources.ExceptionMessages;
* <p>The requestValue has the following format:<br>
*
* <p>requestValue ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objectDN ::= LDAPDN<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; passwd ::= OCTET STRING<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bufferLength ::= INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retunedBuffer::= OCTET STRING<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dataChunkSizes ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp; SEQUENCE {<br>
......@@ -62,9 +67,7 @@ import com.novell.ldap.resources.ExceptionMessages;
* SEQUENCE of {eacChunksize INTEGER}]<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;
* }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objectDN ::= OCTET STRING<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bufferLength ::= INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retunedBuffer::= OCTET STRING</p>
* }<br> </p>
*/
public class LDAPRestoreRequest extends LDAPExtendedOperation {
......@@ -75,40 +78,48 @@ public class LDAPRestoreRequest extends LDAPExtendedOperation {
* restore data.
*
* @param objectDN The object DN to restore
* <br><br>
* <br>
* @param passwd The encrypted password required for the object to
* be backed up
* <br>
* @param bufferLength The length of backed up data
* <br><br>
* @param buffer The data buffer containing chunks sizes and data blob
* <br>
* @param chunkSizesString The String containing number of chunks and
* each chunk elements representing chunk sizes
* <br>
* @param returnedBuffer The actual data in byte[]
* <br><br>
* @exception LDAPException A general exception which includes an error
* message and an LDAP error code.
*/
public LDAPRestoreRequest(String objectDN, int bufferLength, String buffer)
public LDAPRestoreRequest(String objectDN, byte[] passwd,
int bufferLength, String chunkSizesString, byte[] returnedBuffer)
throws LDAPException {
super(BackupRestoreConstants.NLDAP_LDAP_RESTORE_REQUEST, null);
try {
//Verify the validity of arguments
if (objectDN == null || bufferLength == 0 || buffer == null)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
ByteArrayOutputStream encodedData = new ByteArrayOutputStream();
LBEREncoder encoder = new LBEREncoder();
if (objectDN == null || bufferLength == 0 ||
chunkSizesString == null || returnedBuffer == null)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
//If encrypted password has null reference make it null String
if(passwd == null)
passwd = "".getBytes("UTF8");
/*
* From the input argument buffer get::
* From the input argument chunkSizesString get::
* chunkSize => Represents the number of chunks of data returned from server
* sizeOf each chunk => int represents the size of each chunk
* returnedBuffer => Represents the actual data of returned eDirectoty Object
*/
int index;
int chunkSize;
int chunks[] = null;
index = buffer.indexOf(';');
index = chunkSizesString.indexOf(';');
try {
chunkSize = Integer.parseInt(buffer.substring(0, index));
chunkSize = Integer.parseInt(chunkSizesString.substring(0, index));
} catch (NumberFormatException e) {
throw new LDAPLocalException(
"Invalid data buffer send in the request",
......@@ -119,18 +130,35 @@ public class LDAPRestoreRequest extends LDAPExtendedOperation {
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
buffer = buffer.substring(index + 1);
chunkSizesString = chunkSizesString.substring(index + 1);
int chunkIndex;
//Construct chunks array
chunks = new int[chunkSize];
//Iterate through each member in buffer, assign to chunks array elem
/*
* Iterate through each member in buffer and
* assign to chunks array elements
*/
for (int i = 0; i < chunkSize; i++) {
chunkIndex = buffer.indexOf(';');
chunks[i] = Integer.parseInt(buffer.substring(0, chunkIndex));
buffer = buffer.substring(chunkIndex + 1);
chunkIndex = chunkSizesString.indexOf(';');
if(chunkIndex == -1){
chunks[i] = Integer.parseInt(chunkSizesString);
break;
}
chunks[i] = Integer.parseInt(chunkSizesString.substring(0,
chunkIndex));
chunkSizesString = chunkSizesString.substring(chunkIndex + 1);
}
ByteArrayOutputStream encodedData = new ByteArrayOutputStream();
LBEREncoder encoder = new LBEREncoder();
//Form objectDN, passwd, bufferLength, data byte[] as ASN1 Objects
ASN1OctetString asn1_objectDN = new ASN1OctetString(objectDN);
ASN1OctetString asn1_passwd = new ASN1OctetString(passwd);
ASN1Integer asn1_bufferLength = new ASN1Integer(bufferLength);
ASN1OctetString asn1_buffer = new ASN1OctetString(returnedBuffer);
//Form the chunks sequence to be passed to Server
ASN1Sequence asn1_chunksSeq = new ASN1Sequence();
asn1_chunksSeq.add(new ASN1Integer(chunkSize));
......@@ -142,18 +170,14 @@ public class LDAPRestoreRequest extends LDAPExtendedOperation {
asn1_chunksSet.add(tmpSeq);
}
asn1_chunksSeq.add(asn1_chunksSet);
//Form objectDN, bufferLength, buffer ASN1 Objects
ASN1OctetString asn1_objectDN = new ASN1OctetString(objectDN);
ASN1Integer asn1_bufferLength = new ASN1Integer(bufferLength);
ASN1OctetString asn1_buffer = new ASN1OctetString(buffer);
//Encode data to send to server
asn1_chunksSeq.encode(encoder, encodedData);
asn1_objectDN.encode(encoder, encodedData);
asn1_passwd.encode(encoder, encodedData);
asn1_bufferLength.encode(encoder, encodedData);
asn1_buffer.encode(encoder, encodedData);
asn1_chunksSeq.encode(encoder, encodedData);
// set the value of operation specific data
setValue(encodedData.toByteArray());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment