static bool _darwinEthernet_SetupReceive(MetisGenericEther *ether, const char *devstr) { // If we cannot open the Ethernet BPF (likely due to permissions), return // a soft error so we can move past this failure. if ((ether->etherSocket = _darwinEthernet_OpenBfpDevice()) < 0) { return false; } if (!_darwinEthernet_SetDeviceOptions(ether->etherSocket, devstr)) { trapUnrecoverableState("error setting options: %s", strerror(errno)); } if (!_darwinEthernet_SetFilter(ether)) { trapUnrecoverableState("error setting filter: %s", strerror(errno)); } if (ioctl(ether->etherSocket, BIOCGBLEN, ðer->etherBufferLength)) { trapUnrecoverableState("error getting buffer length: %s", strerror(errno)); } return true; }
// ============================================================= LONGBOW_STOP_DEPRECATED_WARNINGS // ============================================================= bool parcPkcs12KeyStore_CreateFile( const char *filename, const char *password, const char *subjectName, unsigned keyLength, unsigned validityDays) { parcSecurity_AssertIsInitialized(); bool result = false; PARCCertificateFactory *factory = parcCertificateFactory_Create(PARCCertificateType_X509, PARCContainerEncoding_DER); PARCBuffer *privateKeyBuffer; PARCCertificate *certificate = parcCertificateFactory_CreateSelfSignedCertificate(factory, &privateKeyBuffer, (char *) subjectName, keyLength, validityDays); parcCertificateFactory_Release(&factory); if (certificate != NULL) { // construct the full PKCS12 keystore to hold the certificate and private key // Extract the private key EVP_PKEY *privateKey = NULL; uint8_t *privateKeyBytes = parcBuffer_Overlay(privateKeyBuffer, parcBuffer_Limit(privateKeyBuffer)); d2i_PrivateKey(EVP_PKEY_RSA, &privateKey, (const unsigned char **) &privateKeyBytes, parcBuffer_Limit(privateKeyBuffer)); parcBuffer_Release(&privateKeyBuffer); // Extract the certificate PARCBuffer *certBuffer = parcCertificate_GetDEREncodedCertificate(certificate); uint8_t *certBytes = parcBuffer_Overlay(certBuffer, parcBuffer_Limit(certBuffer)); X509 *cert = NULL; d2i_X509(&cert, (const unsigned char **) &certBytes, parcBuffer_Limit(certBuffer)); parcCertificate_Release(&certificate); PKCS12 *pkcs12 = PKCS12_create((char *) password, "ccnxuser", privateKey, cert, NULL, 0, 0, 0 /*default iter*/, PKCS12_DEFAULT_ITER /*mac_iter*/, 0); if (pkcs12 != NULL) { int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0600); if (fd != -1) { FILE *fp = fdopen(fd, "wb"); if (fp != NULL) { i2d_PKCS12_fp(fp, pkcs12); fclose(fp); result = true; } else { trapUnrecoverableState("Cannot fdopen(3) the file descriptor %d", fd); } close(fd); } else { trapUnrecoverableState("Cannot open(2) the file '%s': %s", filename, strerror(errno)); } PKCS12_free(pkcs12); X509_free(cert); EVP_PKEY_free(privateKey); } else { unsigned long errcode; while ((errcode = ERR_get_error()) != 0) { fprintf(stderr, "openssl error: %s\n", ERR_error_string(errcode, NULL)); } trapUnrecoverableState("PKCS12_create returned a NULL value."); } } return result; }