Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
7 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
7 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
7 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
7 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
noc1.key
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
7 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
7 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfCrypt.php
77 lines
| 1 | <?php |
| 2 | class wfCrypt { |
| 3 | private static function getPubKey(){ |
| 4 | #Command to generate our keypair was: openssl req -x509 -newkey rsa:2048 -keyout mycert.key -out mycert.pem -nodes -subj "/C=US/ST=Washington/L=Seattle/O=Wordfence/OU=IT/CN=wordfence.com" -days 7300 |
| 5 | #This is a 2048 bit key using SHA256 with RSA. |
| 6 | $key = <<<ENDKEY |
| 7 | -----BEGIN CERTIFICATE----- |
| 8 | MIIDrTCCApWgAwIBAgIJAIg6Va5tcvwyMA0GCSqGSIb3DQEBCwUAMG0xCzAJBgNV |
| 9 | BAYTAlVTMRMwEQYDVQQIDApXYXNoaW5ndG9uMRAwDgYDVQQHDAdTZWF0dGxlMRIw |
| 10 | EAYDVQQKDAlXb3JkZmVuY2UxCzAJBgNVBAsMAklUMRYwFAYDVQQDDA13b3JkZmVu |
| 11 | Y2UuY29tMB4XDTE1MDMxMjA1NTIzMFoXDTM1MDMwNzA1NTIzMFowbTELMAkGA1UE |
| 12 | BhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxEjAQ |
| 13 |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|
| 29 | ENDKEY; |
| 30 | return $key; |
| 31 | } |
| 32 | public static function makeSymHexKey($length){ |
| 33 | return bin2hex(wfWAFUtils::random_bytes($length / 2)); |
| 34 | } |
| 35 | public static function pubCrypt($symKey){ //encrypts a symmetric key and returns it base64 |
| 36 | openssl_public_encrypt($symKey, $encSymKey, self::getPubKey(), OPENSSL_PKCS1_OAEP_PADDING); //The default OPENSSL_PKCS1_PADDING is deprecated. |
| 37 | return base64_encode($encSymKey); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns the payload symmetrically encrypted and signed by the noc1 public key. The payload is converted to JSON, |
| 42 | * encrypted using a randomly-generated symmetric key, and then hashed and signed with the noc1 public key. |
| 43 | * |
| 44 | * This is NOT cryptographically secure for verifying that this server sent or was aware of the context of the |
| 45 | * message, rather it is intended to be used in tandem with verification via another method (e.g., a call that |
| 46 | * validates due to the site URL matching the license key or noc1 does a call itself to the server to retrieve the |
| 47 | * encrypted payload). It is solely a means to provide data to noc1 that only it can read. |
| 48 | * |
| 49 | * @param array $payload |
| 50 | * @return array The encrypted and signed payload in the form array('message' => <encrypted message in hex>, 'signature' => <signature in hex>). |
| 51 | */ |
| 52 | public static function noc1_encrypt($payload) { |
| 53 | $payloadJSON = json_encode($payload); |
| 54 | |
| 55 | $keyData = file_get_contents(dirname(__FILE__) . '/noc1.key'); |
| 56 | $key = @openssl_get_publickey($keyData); |
| 57 | if ($key !== false) { |
| 58 | $symmetricKey = wfWAFUtils::random_bytes(32); |
| 59 | $iv = wfWAFUtils::random_bytes(16); |
| 60 | $encrypted = @openssl_encrypt($payloadJSON, 'aes-256-cbc', $symmetricKey, OPENSSL_RAW_DATA, $iv); |
| 61 | if ($encrypted !== false) { |
| 62 | $success = openssl_public_encrypt($symmetricKey, $symmetricKeyEncrypted, $key, OPENSSL_PKCS1_OAEP_PADDING); |
| 63 | if ($success) { |
| 64 | $message = $iv . $symmetricKeyEncrypted . $encrypted; |
| 65 | $signatureRaw = hash('sha256', $message, true); |
| 66 | $success = openssl_public_encrypt($signatureRaw, $signature, $key, OPENSSL_PKCS1_OAEP_PADDING); |
| 67 | if ($success) { |
| 68 | $package = array('message' => bin2hex($message), 'signature' => bin2hex($signature)); |
| 69 | return $package; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | return array(); |
| 75 | } |
| 76 | } |
| 77 |