* @param[in] certFileName pointer to null-terminated string with file name
* @return PKI_SUCCESS if success, error code otherwise
*/
-PKIError GenerateDERCertificateFile (const ByteArray *certificate, const char *certFileName);
+PKIError GenerateDERCertificateFile (const ByteArray *certificate, const char * const certFileName);
/**
* Issues certificate signing request with specified parameters.
#include "crlresource.h"
#include "oic_malloc.h"
+#ifdef __unix__
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif // __unix__
+
/* The first octet of the OCTET STRING indicates whether the key is
compressed or uncompressed. The uncompressed form is indicated by 0x04
and the compressed form is indicated by either 0x02 or 0x03 (RFC 5480)*/
);
}
-PKIError GenerateDERCertificateFile (const ByteArray *certificate, const char *certFileName)
+PKIError GenerateDERCertificateFile (const ByteArray *certificate, const char * const certFileName)
{
FUNCTION_INIT();
+
+#ifdef __unix__
+ struct stat st;
+ int fd = -1;
+#else
FILE *filePointer = NULL;
+#endif
CHECK_NULL(certFileName, ISSUER_NULL_PASSED);
CHECK_NULL(certificate, ISSUER_NULL_PASSED);
CHECK_NULL(certificate->data, ISSUER_NULL_PASSED);
+
+#ifdef __unix__
+ fd = open(certFileName, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+ CHECK_NOT_EQUAL(fd, -1, ISSUER_NULL_PASSED);
+ CHECK_EQUAL(fstat(fd, &st), 0, ISSUER_NULL_PASSED);
+ CHECK_COND(S_ISREG(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ CHECK_COND(!S_ISLNK(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ CHECK_EQUAL(write(fd, certificate->data, certificate->len), (ssize_t) certificate->len,
+ ISSUER_FILE_WRITE_ERROR);
+
+ FUNCTION_CLEAR(
+ if(-1 != fd)
+ {
+ close(fd);
+ }
+ );
+#else
filePointer = fopen(certFileName, "wb");
CHECK_NULL(filePointer, ISSUER_FILE_WRITE_ERROR);
CHECK_EQUAL(fwrite(certificate->data, 1, certificate->len, filePointer), certificate->len,
FUNCTION_CLEAR(
if(filePointer)
- {
- fclose(filePointer);
- }
+ {
+ fclose(filePointer);
+ }
filePointer = NULL;
);
+#endif
+
}
PKIError SetSerialNumber (const long serNum)
#include "crlresource.h"
#include "crl_generator.h"
+#ifdef __unix__
+#include <sys/stat.h>
+#endif // __unix__
+
//constants used in ckmInfo
#define CKM_INFO_IS_NOT_LOADED (0)
#define CKM_INFO_IS_LOADED (1)
}
else ////create new storage
{
+#ifdef __unix__
+ struct stat st;
+ if (0 == lstat(CA_STORAGE_FILE, &st))
+ {
+ CHECK_COND(S_ISREG(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ CHECK_COND(!S_ISLNK(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ }
+#endif
filePointer = fopen(CA_STORAGE_FILE, "wb");
CHECK_NULL(filePointer, ISSUER_CA_STORAGE_FILE_WRITE_ERROR);
objectsWrote = fwrite(&g_ckmInfo, sizeof(CKMInfo_t), count, filePointer);
FILE *filePointer = NULL;
int count = 1;
int objectsWrote = 0;
+#ifdef __unix__
+ struct stat st;
+#endif
CHECK_COND(g_ckmInfo.CKMInfoIsLoaded, CKM_INFO_IS_NOT_INIT);
+#ifdef __unix__
+ if (0 == lstat(CA_STORAGE_FILE, &st))
+ {
+ CHECK_COND(S_ISREG(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ CHECK_COND(!S_ISLNK(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ }
+#endif
filePointer = fopen(CA_STORAGE_FILE, "wb");
CHECK_NULL(filePointer, ISSUER_CA_STORAGE_FILE_WRITE_ERROR);
objectsWrote = fwrite(&g_ckmInfo, sizeof(CKMInfo_t), count, filePointer);
FILE *filePointer = NULL;
uint32_t objectsWrote = 0;
uint8_t prefix[CERT_LEN_PREFIX] = {0};
-
+#ifdef __unix__
+ struct stat st;
+ if (0 == lstat(CA_STORAGE_CRT_FILE, &st))
+ {
+ CHECK_COND(S_ISREG(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ CHECK_COND(!S_ISLNK(st.st_mode), ISSUER_FILE_WRITE_ERROR);
+ }
+#endif
filePointer = fopen(CA_STORAGE_CRT_FILE, "wb");
CHECK_NULL(filePointer, ISSUER_CA_STORAGE_CRT_WRITE_ERROR);
* Persistent storage handlers. An APP must provide OCPersistentStorage handler pointers
* when it calls OCRegisterPersistentStorageHandler.
* Persistent storage open handler points to default file path.
+ * It should check file path and whether the file is symbolic link or no.
* Application can point to appropriate SVR database path for it's IoTivity Server.
*/
typedef struct {