UniMate API Reference for Objective-C Language: Difference between revisions

From SecuTech Wiki
Jump to navigationJump to search
Joseph (talk | contribs)
No edit summary
Bao (talk | contribs)
mNo edit summary
 
(26 intermediate revisions by 2 users not shown)
Line 5: Line 5:
=== Relative Convention ===
=== Relative Convention ===


==== Character Coding ====
==== Character Encoding ====


All string parameters use the UTF-8 coding standard.
All string parameters use the UTF-8 coding standard.
Line 11: Line 11:
==== Return Value ====
==== Return Value ====


All return values from functions are of type long.
All function return values are of type long.


0 refers to success, whereas < 0 indicates an error code.
0 refers to success, whereas < 0 indicates some error has occurred.


==== Public Key Format ====
==== Public Key Format ====


<code>pPublicKey</code> is compatible with RFC 3447 specification.
<code>pPublicKey</code> is compatible with the RFC 3447 specification.


<pre>
<pre>
Line 28: Line 28:
==== Hash Algorithm Identification ====
==== Hash Algorithm Identification ====


pHashOID is the identification string of each hash algorithm, and the specific algorithm ID are as the following table.
<code>pHashOID</code> is the identification string of each hash algorithm, and the specific algorithm IDs are listed in the following table.


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>ID</th>
<th>ID</th>
Line 47: Line 47:
==== Ease of Use Convention ====
==== Ease of Use Convention ====
<!--Review-->
<!--Review-->
As the speed of reading a certificate is low, an initiation mechanism shall be established, that is after the content of a public key is read at the first time of inserting a key, the public key and the information of the corresponding private key, such as container name, container ID and etc, shall be stored together in a configure file (the configure file will be created automatically: such as "company name.config") to ensure that at the next time, the public key and private key-pair can be established by just reading the private ID in the key. Through this method, the speed of certificate reading will be improved, and meanwhile the private key can be found very fast when signing or decrypting digital envelope.
As the speed of reading a certificate is slow, an initiation mechanism shall be established, that is after the content of a public key is read for the first time when inserting a key, the public key and the information regarding the corresponding private key; such as container name, container ID, etc, shall be stored together in a configuration file (this configuration file will be created automatically: such as "company name.config") to ensure that when next run, the public key and private key-pair can be established just by reading the private ID in the key. Improving the speed at which a certificate is read, and allowing the private key to be found quicker when signing or decrypting a digital envelope.


==== Third Party Encrypt Library ====
==== Third Party Encrypt Library ====


If using encrypt library, please use OpenSSL (openssl1.0.0e) library file compiled by SecuTech.
If using the encrypt library, please use the OpenSSL (openssl1.0.0e) library file compiled by SecuTech.


==== Relative Development ====
==== Relative Development ====


Add "Company_product ID" into the name of code file in OC; add "Company_product ID" into the name of C and C++ source code file, function, and global variable to avoid conflict with other companies’ products in the upper compiled.
Add "Company_product ID" into the name of the code file in Objective-C, add "Company_product ID" into the name of the C and C++ source code file, function, and global variable to avoid conflict with any other company's products during compilation.


Realize the main function of the protocol function, and if it has a return value which is released automatically (not alloc), retain must be added.
Consider the main function of the prototype function, and if it has a return value which is released automatically (not alloc'ed), if so, retain must be added.


==== Development Tools ====
==== Development Tools ====
Line 68: Line 68:
=== Interface Definition ===
=== Interface Definition ===


==== Check a Device Connection Status ====
==== Check Device Connection Status ====


<code>-(long ) isConnected:(bool *) pConnected;</code>
<code>-(long) isConnected:(bool *) pConnected;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 81: Line 81:
<tr>
<tr>
<td>pConnected</td>
<td>pConnected</td>
<td>[out] If device is connected or not.</td>
<td>[out] Device connection status</td>
</tr>
</tr>
</table>
</table>
Line 87: Line 87:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 105: Line 105:
</table>
</table>


==== Generate a Key-pair ====


<code>-(long ) createRSAKey:(NSString *) pPassword publicKeyLength:( NSInteger)publicKeyLength ppPublicKey:(NSData **) ppPublicKey</code>
==== Generate RSA Key Pair ====
 
<code>-(long) createRSAKey:(NSString *) pPassword publicKeyLength:(NSInteger) publicKeyLength ppPublicKey:(NSData **) ppPublicKey;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 122: Line 123:
<tr>
<tr>
<td>publicKeyLength</td>
<td>publicKeyLength</td>
<td>[in] Length of public key (bit), 1024 or 2048</td>
<td>[in] Length of public key: 1024 or 2048 bits</td>
</tr>
</tr>
<tr>
<tr>
<td>ppPublicKey</td>
<td>ppPublicKey</td>
<td>[out] Public key of the generated key-pair (format comply with the coding specification described in this document)</td>
<td>[out] Public key of the generated key-pair (format complies with the coding specification described in this document)</td>
</tr>
</tr>
</table>
</table>
Line 132: Line 133:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 150: Line 151:
</table>
</table>


==== Import a Public Key Certificate ====


<code>-(long )importX509Certificate:(NSData *) pCertificate;</code>
==== Import Public Key Certificate ====
 
<code>-(long) importX509Certificate:(NSData *) pCertificate;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 163: Line 165:
<tr>
<tr>
<td>pCertificate</td>
<td>pCertificate</td>
<td>[in] Der coded X509 public key certificate</td>
<td>[in] DER coded X509 public key certificate</td>
</tr>
</tr>
</table>
</table>
Line 169: Line 171:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 189: Line 191:
==== Decrypt Digital Envelope ====
==== Decrypt Digital Envelope ====


<code>-(long ) decryptEnvelopeData: (NSData *) pCertificate
<code>-(long) decryptEnvelopeData:(NSData *) pCertificate
pPassword:(NSString *) pPassword
pPassword:(NSString *) pPassword
inData:( NSData *) inData
inData:(NSData *) inData
ppOutData:(NSData**) ppOutData;</code>
ppOutData:(NSData **) ppOutData;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 203: Line 205:
<tr>
<tr>
<td>pCertificate</td>
<td>pCertificate</td>
<td>[in] Public key certificate corresponding to the private key, which is the decrypting certificate</td>
<td>[in] Public key certificate corresponding to the private key; the decrypting certificate</td>
</tr>
</tr>
<tr>
<tr>
Line 215: Line 217:
<tr>
<tr>
<td>ppOutData</td>
<td>ppOutData</td>
<td>[out] Original text of digital envelope</td>
<td>[out] Plain text of digital envelope</td>
</tr>
</tr>
</table>
</table>
Line 221: Line 223:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 239: Line 241:
</table>
</table>


==== Digital Sign (including explicit key signature, ordinary signature, SSL handling, and P10 signature) ====
==== Sign Data ====


<code>-(long ) signData: (NSData *) pCertificate
Includes explicit key signature, ordinary signature, SSL handling, and P10 signature.
 
<code>-(long) signData:(NSData *) pCertificate
pPassword:(NSString *) pPassword
pPassword:(NSString *) pPassword
srcData:( NSData *) srcData
srcData:(NSData *) srcData
pHashOID:( NSString *) pHashOID
pHashOID:(NSString *) pHashOID
ppOutData:(NSData**) ppOutData;</code>
ppOutData:(NSData **) ppOutData;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 256: Line 260:
<tr>
<tr>
<td>pCertificate</td>
<td>pCertificate</td>
<td>[in] Public key certificate corresponding to private key, and if RSA key pairs are just generated, use the public key value returned from createRSAkey function.</td>
<td>[in] Public key certificate corresponding to the private key. If using RSA generated key pairs, use the public key value returned from the createRSAkey function.</td>
</tr>
</tr>
<tr>
<tr>
Line 272: Line 276:
<tr>
<tr>
<td>ppOutData</td>
<td>ppOutData</td>
<td>[out] Signed data (PKCS1 format, without adding complementing bits)</td>
<td>[out] Signed data (PKCS#1 format, without adding complementing bits)</td>
</tr>
</tr>
</table>
</table>
Line 278: Line 282:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 296: Line 300:
</table>
</table>


==== Change a Device Password ====
==== Change Password ====


<code>-(long ) changePassword:(NSData *)pCertificate oldPwd:(NSString *) oldPwd newPwd:(NSString*)newPwd;</code>
<code>-(long) changePassword:(NSData *) pCertificate oldPwd:(NSString *) oldPwd newPwd:(NSString *) newPwd;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 309: Line 313:
<tr>
<tr>
<td>pCertificate</td>
<td>pCertificate</td>
<td>[in] Public key certificate, and if it’s device password, ignore this parmeters.</td>
<td>[in] Public key certificate. If inputting device password, ignore this parameter</td>
</tr>
</tr>
<tr>
<tr>
Line 323: Line 327:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 340: Line 344:
</tr>
</tr>
</table>
</table>


==== Get DER Code of Public Key Certificate ====
==== Get DER Code of Public Key Certificate ====
<code>-(long ) getX509Certificates:(NSArray **) ppCertificates;</code>
 
<code>-(long) getX509Certificates:(NSArray **) ppCertificates;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 359: Line 365:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 377: Line 383:
</table>
</table>


==== Get the Remaining Number of Password Attempts ====


<code>-(long ) getPwdCanRetries: (NSData *) pCertificate pRemaining :(int *) pRemaining;</code>
==== Get the Remaining Number of Password Login Attempts ====
 
<code>-(long) getPwdCanRetries:(NSData *) pCertificate pRemaining:(int *) pRemaining;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 390: Line 397:
<tr>
<tr>
<td>pCertificate</td>
<td>pCertificate</td>
<td>[in] Public key certificate, and if it’s the device password, ignore this parameter.</td>
<td>[in] Public key certificate. If inputting the device password, ignore this parameter</td>
</tr>
</tr>
<tr>
<tr>
<td>pRremaining</td>
<td>pRremaining</td>
<td>[out] The remaining number of password attempts</td>
<td>[out] Remaining number of password attempts</td>
</tr>
</tr>
</table>
</table>
Line 400: Line 407:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 418: Line 425:
</table>
</table>


==== Get a Device ID (the unique ID of a device) ====
==== Get a Device Serial Number ====
 
The serial number is the device's unique ID.


<code>-(long ) getDeviceSerialNumber:(NSString **)ppDeviceSN;</code>
<code>-(long) getDeviceSerialNumber:(NSString **) ppDeviceSN;</code>


'''Parameters'''
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Parameter</th>
<th>Parameter</th>
Line 431: Line 440:
<tr>
<tr>
<td>ppDeviceSN</td>
<td>ppDeviceSN</td>
<td>[out] Device ID</td>
<td>[out] Device serial number</td>
</tr>
</tr>
</table>
</table>
Line 437: Line 446:
'''Return values'''
'''Return values'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Result</th>
<th>Result</th>
Line 455: Line 464:
</table>
</table>


=== Error Code Table ===
==== Get a Random Number ====
Provide a randomly generated number.
 
<code>-(long) getRandomNumber:(NSString **) randomNum ran_len:(unsigned long) ran_len;</code>
 
'''Parameters'''


<table border="1">
<table class="wikitable">
<tr>
<tr>
<th>Error Code</th>
<th>Parameter</th>
<th>Macro Definition</th>
<th>Description</th>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
<td>0 </td>
<td>ran_len</td>
<td>S_OK </td>
<td>[in] Random number length</td>
<td>Success</td>
</tr>
</tr>
<tr>
<tr>
<td>-1 </td>
<td>randomNum</td>
<td>S_DEVICE_FAILURE </td>
<td>[out] Random number generated</td>
<td>No connection</td>
</tr>
</tr>
</table>
'''Return values'''
<table class="wikitable">
<tr>
<tr>
<td>-2 </td>
<th>Result</th>
<td>S_INVALID_PASSWORD </td>
<th>Value</th>
<td>Verify password failed</td>
<th>Description</th>
</tr>
</tr>
<tr>
<tr>
<td>-3 </td>
<td>0</td>
<td>S_DEVICE_LOCK </td>
<td>S_OK</td>
<td>Device Locked</td>
<td>Success</td>
</tr>
</tr>
<tr>
<tr>
<td>-4 </td>
<td>< 0</td>
<td>S_NOT_ENOUGH_MEMORY </td>
<td>Error code</td>
<td>Insufficient memory</td>
<td>See error code description</td>
</tr>
<tr>
<td>-5 </td>
<td>S_INVALID_CERTIFICATE </td>
<td>Invalid format of Certificate</td>
</tr>
<tr>
<td>-6 </td>
<td>S_INVALID_ALGORITHM </td>
<td>Invalid algorithm</td>
</tr>
<tr>
<td>-7 </td>
<td>S_INVALID_PARAMETER </td>
<td>Invalid parameter</td>
</tr>
<tr>
<td>-8 </td>
<td>S_UNKOWN_ERROR </td>
<td>Unknown error</td>
</tr>
<tr>
<td>-9 </td>
<td>S_USER_CANCEL </td>
<td>Canceled by user</td>
</tr>
</tr>
</table>
</table>

Latest revision as of 13:54, 10 August 2016


UniMate Mobile Certificate API Reference

Relative Convention

Character Encoding

All string parameters use the UTF-8 coding standard.

Return Value

All function return values are of type long.

0 refers to success, whereas < 0 indicates some error has occurred.

Public Key Format

pPublicKey is compatible with the RFC 3447 specification.

RSAPublicKey ::= SEQUENCE {
    modulus 		INTEGER -- n
    publicExponent 	INTEGER -- e
}

Hash Algorithm Identification

pHashOID is the identification string of each hash algorithm, and the specific algorithm IDs are listed in the following table.

ID Specification
1.3.14.3.2.26 SHA1 Algorithm
2.16.840.1.101.3.4.2.1 SHA256 Algorithm

Ease of Use Convention

As the speed of reading a certificate is slow, an initiation mechanism shall be established, that is after the content of a public key is read for the first time when inserting a key, the public key and the information regarding the corresponding private key; such as container name, container ID, etc, shall be stored together in a configuration file (this configuration file will be created automatically: such as "company name.config") to ensure that when next run, the public key and private key-pair can be established just by reading the private ID in the key. Improving the speed at which a certificate is read, and allowing the private key to be found quicker when signing or decrypting a digital envelope.

Third Party Encrypt Library

If using the encrypt library, please use the OpenSSL (openssl1.0.0e) library file compiled by SecuTech.

Relative Development

Add "Company_product ID" into the name of the code file in Objective-C, add "Company_product ID" into the name of the C and C++ source code file, function, and global variable to avoid conflict with any other company's products during compilation.

Consider the main function of the prototype function, and if it has a return value which is released automatically (not alloc'ed), if so, retain must be added.

Development Tools

  • XCODE tools version 4.0 or higher.
  • System default LLVM compiler 3.0.
  • Support iOS SDK version 4.2 or higher (iOS deployment Target: iOS 4.2).
  • Active Architecture: ARM v6.

Interface Definition

Check Device Connection Status

-(long) isConnected:(bool *) pConnected;

Parameters

Parameter Description
pConnected [out] Device connection status

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description


Generate RSA Key Pair

-(long) createRSAKey:(NSString *) pPassword publicKeyLength:(NSInteger) publicKeyLength ppPublicKey:(NSData **) ppPublicKey;

Parameters

Parameter Description
pPassword [in] Device password
publicKeyLength [in] Length of public key: 1024 or 2048 bits
ppPublicKey [out] Public key of the generated key-pair (format complies with the coding specification described in this document)

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description


Import Public Key Certificate

-(long) importX509Certificate:(NSData *) pCertificate;

Parameters

Parameter Description
pCertificate [in] DER coded X509 public key certificate

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description

Decrypt Digital Envelope

-(long) decryptEnvelopeData:(NSData *) pCertificate pPassword:(NSString *) pPassword inData:(NSData *) inData ppOutData:(NSData **) ppOutData;

Parameters

Parameter Description
pCertificate [in] Public key certificate corresponding to the private key; the decrypting certificate
pPassword [in] Device password
inData [in] Cipher text of digital envelope
ppOutData [out] Plain text of digital envelope

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description

Sign Data

Includes explicit key signature, ordinary signature, SSL handling, and P10 signature.

-(long) signData:(NSData *) pCertificate pPassword:(NSString *) pPassword srcData:(NSData *) srcData pHashOID:(NSString *) pHashOID ppOutData:(NSData **) ppOutData;

Parameters

Parameter Description
pCertificate [in] Public key certificate corresponding to the private key. If using RSA generated key pairs, use the public key value returned from the createRSAkey function.
pPassword [in] Device password
srcData [in] Source data to be signed
pHashOID [in] Hash algorithm identification
ppOutData [out] Signed data (PKCS#1 format, without adding complementing bits)

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description

Change Password

-(long) changePassword:(NSData *) pCertificate oldPwd:(NSString *) oldPwd newPwd:(NSString *) newPwd;

Parameters

Parameter Description
pCertificate [in] Public key certificate. If inputting device password, ignore this parameter
oldPwd [in] Old password
newPwd [in] New password

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description


Get DER Code of Public Key Certificate

-(long) getX509Certificates:(NSArray **) ppCertificates;

Parameters

Parameter Description
ppCertificates [out] Public key certificate DER coded NSData array

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description


Get the Remaining Number of Password Login Attempts

-(long) getPwdCanRetries:(NSData *) pCertificate pRemaining:(int *) pRemaining;

Parameters

Parameter Description
pCertificate [in] Public key certificate. If inputting the device password, ignore this parameter
pRremaining [out] Remaining number of password attempts

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description

Get a Device Serial Number

The serial number is the device's unique ID.

-(long) getDeviceSerialNumber:(NSString **) ppDeviceSN;

Parameters

Parameter Description
ppDeviceSN [out] Device serial number

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description

Get a Random Number

Provide a randomly generated number.

-(long) getRandomNumber:(NSString **) randomNum ran_len:(unsigned long) ran_len;

Parameters

Parameter Description
ran_len [in] Random number length
randomNum [out] Random number generated

Return values

Result Value Description
0 S_OK Success
< 0 Error code See error code description