replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / credresource.h
index 52e105c..1806540 100644 (file)
@@ -57,6 +57,18 @@ OCStackResult DeInitCredResource();
 OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
 
 /**
+ * This method is used by SRM to retrieve credential entry for given credId.
+ *
+ * @note Caller needs to release this memory by calling DeleteCredList().
+ *
+ * @param credId for which credential is required.
+ *
+ * @return reference to @ref OicSecCred_t, if credential is found, else NULL, if credential
+ * not found.
+ */
+OicSecCred_t* GetCredEntryByCredId(const uint16_t credId);
+
+/**
  * This function converts credential data into CBOR format.
  * Caller needs to invoke 'free' when done using returned string.
  *
@@ -70,6 +82,19 @@ OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
 OCStackResult CredToCBORPayload(const OicSecCred_t* cred, uint8_t **cborPayload,
                                 size_t *cborSize, int secureFlag);
 
+#ifdef MULTIPLE_OWNER
+/**
+ * Function to check the credential access of SubOwner
+ *
+ * @param[in] uuid SubOwner's UUID
+ * @param[in] cborPayload CBOR payload of credential
+ * @param[in] size Byte length of cborPayload
+ *
+ * @return ::true for valid access, otherwise invalid access
+ */
+bool IsValidCredentialAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPayload, size_t size);
+#endif //MULTIPLE_OWNER
+
 /**
  * This function generates the bin credential data.
  *
@@ -78,13 +103,14 @@ OCStackResult CredToCBORPayload(const OicSecCred_t* cred, uint8_t **cborPayload,
  * @param publicData public data such as public key.
  * @param privateData private data such as private key.
  * @param rownerID Resource owner's UUID.
+ * @param eownerID Entry owner's UUID.
  *
  * @return pointer to instance of @ref OicSecCred_t if successful. else NULL in case of error.
 
  */
 OicSecCred_t * GenerateCredential(const OicUuid_t* subject, OicSecCredType_t credType,
-                     const OicSecCert_t * publicData, const OicSecKey_t * privateData,
-                     const OicUuid_t * rownerID);
+                     const OicSecKey_t * publicData, const OicSecKey_t * privateData,
+                     const OicUuid_t * rownerID, const OicUuid_t * eownerID);
 
 /**
  * This function adds the new cred to the credential list.
@@ -99,13 +125,22 @@ OCStackResult AddCredential(OicSecCred_t * cred);
 /**
  * Function to remove the credential from SVR DB.
  *
+ * @param subject is the Credential Subject to be deleted.
+ *
+ * @return ::OC_STACK_OK for success, or errorcode otherwise.
+ */
+OCStackResult RemoveCredential(const OicUuid_t *subject);
+
+/**
+ * Function to remove the credential from SVR DB.
+ *
  * @param credId is the Credential ID to be deleted.
  *
  * @return ::OC_STACK_OK for success, or errorcode otherwise.
  */
-OCStackResult RemoveCredential(const OicUuid_t *credId);
+OCStackResult RemoveCredentialByCredId(uint16_t credId);
 
-#if defined(__WITH_DTLS__)
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
 /**
  * This internal callback is used by lower stack (i.e. CA layer) to
  * retrieve PSK credentials from RI security layer.
@@ -140,18 +175,14 @@ OCStackResult AddTmpPskWithPIN(const OicUuid_t* tmpSubject, OicSecCredType_t cre
                             const OicUuid_t * rownerID,
                             OicUuid_t* tmpCredSubject);
 
-#endif /* __WITH_DTLS__ */
+#endif // __WITH_DTLS__ or __WITH_TLS__
 
-#ifdef __WITH_X509__
 /**
- * This function is used toretrieve certificate credentials from RI security layer.
- *
- * @param credInfo is the binary structure containing certificate credentials
+ * Function to getting credential list
  *
- * @return 0 on success.
+ * @return ::credential list
  */
-int GetDtlsX509Credentials(CADtlsX509Creds_t *credInfo);
-#endif /*__WITH_X509__*/
+const OicSecCred_t* GetCredList();
 
 /**
  * Function to deallocate allocated memory to OicSecCred_t.
@@ -178,22 +209,57 @@ OCStackResult SetCredRownerId(const OicUuid_t* newROwner);
  */
 OCStackResult GetCredRownerId(OicUuid_t *rowneruuid);
 
-#ifdef __WITH_TLS__
+#if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
 /**
- * @def CA_SUBJECT_ID
- * @brief subject uuid for credential with CA certificates
+ * Used by mbedTLS to retrieve trusted CA certificates
+ *
+ * @param[out] crt certificates to be filled.
+ * @param[in] usage credential usage string.
  */
-#define CA_SUBJECT_ID ("00000000-0000-0000-0000-000000000000")
+void GetDerCaCert(ByteArray_t * crt, const char * usage);
 /**
- * Adds the new CA to the chain
+ * Used by mbedTLS to retrieve own certificate chain
  *
- * @param cert is the pointer to DER encoded certificate
+ * @param[out] crt certificate chain to be filled.
+ * @param[in] usage credential usage string.
+ */
+void GetDerOwnCert(ByteArray_t * crt, const char * usage);
+/**
+ * Used by mbedTLS to retrieve owm private key
  *
- * @return ::OC_STACK_OK, cert not NULL and persistent storage gets updated.
- * ::OC_STACK_ERROR, cert is NULL or fails to update persistent storage.
+ * @param[out] key key to be filled.
+ * @param[in] usage credential usage string.
  */
-OCStackResult AddCA(OicSecCert_t * cert);
-#endif
+void GetDerKey(ByteArray_t * key, const char * usage);
+/**
+ * Used by CA to retrieve credential types
+ *
+ * @param[out] key key to be filled.
+ * @param[in] usage credential usage string.
+ */
+void InitCipherSuiteListInternal(bool *list, const char * usage);
+
+
+
+
+//Added as workaround by Chul Lee.
+OCStackResult CredSaveTrustCertChain(const OicUuid_t* subject, uint8_t *trustCertChain, size_t chainSize,
+                                            OicEncodingType_t encodingType,  const char* usage, uint16_t *credId);
+
+OCStackResult CredSaveOwnCert(const OicUuid_t* subject, OicSecKey_t* cert, OicSecKey_t * key,
+                                    const char* usage, uint16_t *credId);
+
+/**
+ * API to add preconfigured PIN for MOT
+ *
+ * @param[in] preconfPin string type of preconfigured PIN
+ *
+ * @retval ::OC_STACK_OK for Success, otherwise some error value
+ */
+OCStackResult AddPreconfPinCredential(const char* preconfPin);
+
+
+#endif // __WITH_TLS__
 #ifdef __cplusplus
 }
 #endif