├── .gitignore ├── .gitmodules ├── Algorithm.cpp ├── Algorithm.h ├── Base64.cpp ├── Base64.h ├── CMakeLists.txt ├── Chrome └── chromepackage │ └── manifest.json ├── CryptoOperation.cpp ├── CryptoOperation.h ├── Factory.cpp ├── Key.cpp ├── Key.h ├── KeyOperation.cpp ├── KeyOperation.h ├── LICENSE ├── Mac ├── CryptoOperationImpl.cpp ├── CryptoOperationImpl.h ├── KeyImpl.cpp ├── KeyImpl.h ├── MacUtils.cpp ├── MacUtils.h ├── WebCryptoKeyandCertificateDiscoveryAPI.cpp ├── X509CertificateMac.cpp ├── X509CertificateMac.h ├── X509CertificateSelectorWorkerFunc.cpp ├── bundle_template │ ├── Info.plist │ ├── InfoPlist.strings │ └── Localized.r ├── dmg_template │ ├── .background │ │ ├── PLACE_BACKGROUND_PICTURE_HERE.txt │ │ └── background.png │ └── README.txt ├── dmgdesign.applescript ├── installer.cmake └── projectDef.cmake ├── NOTICE ├── PluginConfig.cmake ├── README.md ├── Test └── test.html ├── WebCryptoKeyandCertificateDiscovery.cpp ├── WebCryptoKeyandCertificateDiscovery.h ├── WebCryptoKeyandCertificateDiscoveryAPI.cpp ├── WebCryptoKeyandCertificateDiscoveryAPI.h ├── Win ├── WebCryptoKeyandCertificateDiscoveryAPI.cpp ├── WiX │ ├── WebCryptoKeyandCertificateDiscovery.ddf │ ├── WebCryptoKeyandCertificateDiscovery.inf │ └── WebCryptoKeyandCertificateDiscoveryInstaller.wxs ├── X509CertificateImpl.cpp ├── X509CertificateImpl.h ├── X509CertificateImpl.hpp ├── X509CertificateSelectorWorkerFunc.cpp └── projectDef.cmake ├── X11 └── projectDef.cmake ├── X500Principal.cpp ├── X500Principal.h ├── X509Certificate.cpp ├── X509Certificate.h ├── X509CertificateSelector.cpp ├── X509CertificateSelector.h ├── prep2012.cmd ├── prep2012x64.cmd ├── prepmac.sh └── xpi └── content ├── chrome.manifest └── install.rdf /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "firebreath"] 2 | path = firebreath 3 | url = http://github.com/nvdbleek/FireBreath.git 4 | -------------------------------------------------------------------------------- /Algorithm.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // Algorithm.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 29/03/13. 20 | // 21 | // 22 | 23 | #include "Algorithm.h" 24 | 25 | Algorithm::Algorithm(const FB::BrowserHostPtr& host, std::string name, FB::VariantMap params) : JSAPIAuto(name), m_host(host), m_name(name), m_params(params) 26 | { 27 | initializeProperties(); 28 | } 29 | 30 | Algorithm::Algorithm(const Algorithm&other) : JSAPIAuto(std::string(other.m_name.begin(), other.m_name.end())), m_host(other.m_host), m_name(other.m_name), m_params(other.m_params) 31 | { 32 | initializeProperties(); 33 | } 34 | 35 | Algorithm& Algorithm::operator=(const Algorithm& other) 36 | { 37 | m_host = other.m_host; 38 | m_name = other.m_name; 39 | m_params = other.m_params; 40 | 41 | initializeProperties(); 42 | 43 | return *this; 44 | } 45 | 46 | std::string Algorithm::get_name() 47 | { 48 | return m_name; 49 | } 50 | 51 | FB::VariantMap Algorithm::get_params() 52 | { 53 | return m_params; 54 | } 55 | void Algorithm::initializeProperties() 56 | { 57 | registerProperty("name", make_property(this, &Algorithm::get_name)); 58 | registerProperty("params", make_property(this, &Algorithm::get_params)); 59 | } 60 | -------------------------------------------------------------------------------- /Algorithm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // Algorithm.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 29/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__Algorithm__ 24 | #define __FireBreath__Algorithm__ 25 | 26 | #include 27 | 28 | #include "JSAPIAuto.h" 29 | #include "BrowserHost.h" 30 | 31 | 32 | class Algorithm : public FB::JSAPIAuto 33 | { 34 | public: 35 | Algorithm(const FB::BrowserHostPtr& host, std::string name, FB::VariantMap params); 36 | virtual ~Algorithm() {}; 37 | 38 | Algorithm(const Algorithm& other); 39 | Algorithm& operator=(const Algorithm& other); 40 | 41 | std::string get_name(); 42 | FB::VariantMap get_params(); 43 | 44 | private: 45 | FB::BrowserHostPtr m_host; 46 | std::string m_name; 47 | FB::VariantMap m_params; 48 | 49 | private: 50 | void initializeProperties(); 51 | }; 52 | 53 | #endif /* defined(__FireBreath__Algorithm__) */ 54 | -------------------------------------------------------------------------------- /Base64.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // Base64.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 05/04/13. 20 | // 21 | 22 | #include 23 | 24 | #include "Base64.h" 25 | 26 | char Base64::m_encodingTable[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 27 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 28 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 29 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 30 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 31 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 32 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 33 | '4', '5', '6', '7', '8', '9', '+', '/'}; 34 | char* Base64::m_decodingTable = NULL; 35 | int Base64::m_modTable[] = {0, 2, 1}; 36 | 37 | 38 | 39 | std::string Base64::encode(unsigned char *buffer, int inputLength) 40 | { 41 | int resultLength = 4 * ((inputLength + 2) / 3); 42 | 43 | char *encoded_data = new char[resultLength]; 44 | if (encoded_data == NULL) return NULL; 45 | 46 | for (int i = 0, j = 0; i < inputLength;) { 47 | 48 | uint32_t octet_a = i < inputLength ? buffer[i++] : 0; 49 | uint32_t octet_b = i < inputLength ? buffer[i++] : 0; 50 | uint32_t octet_c = i < inputLength ? buffer[i++] : 0; 51 | 52 | uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; 53 | 54 | encoded_data[j++] = m_encodingTable[(triple >> 3 * 6) & 0x3F]; 55 | encoded_data[j++] = m_encodingTable[(triple >> 2 * 6) & 0x3F]; 56 | encoded_data[j++] = m_encodingTable[(triple >> 1 * 6) & 0x3F]; 57 | encoded_data[j++] = m_encodingTable[(triple >> 0 * 6) & 0x3F]; 58 | } 59 | 60 | for (int i = 0; i < m_modTable[inputLength % 3]; i++) 61 | encoded_data[resultLength - 1 - i] = '='; 62 | 63 | std::string result= std::string(encoded_data, resultLength); 64 | delete encoded_data; 65 | 66 | return result; 67 | } 68 | 69 | 70 | 71 | char *Base64::decode(std::string base64, int *resultLength) 72 | { 73 | 74 | if (m_decodingTable == NULL) build_decoding_table(); 75 | 76 | int inputLength = base64.length(); 77 | if (inputLength % 4 != 0) return NULL; 78 | 79 | *resultLength = inputLength / 4 * 3; 80 | if (base64[inputLength - 1] == '=') (*resultLength)--; 81 | if (base64[inputLength - 2] == '=') (*resultLength)--; 82 | 83 | char *decodedData = new char[*resultLength]; 84 | if (decodedData == NULL) return NULL; 85 | 86 | for (int i = 0, j = 0; i < inputLength;) { 87 | 88 | uint32_t sextet_a = base64[i] == '=' ? 0 & i++ : m_decodingTable[(int)base64[i++]&0xFF]; 89 | uint32_t sextet_b = base64[i] == '=' ? 0 & i++ : m_decodingTable[(int)base64[i++]&0xFF]; 90 | uint32_t sextet_c = base64[i] == '=' ? 0 & i++ : m_decodingTable[(int)base64[i++]&0xFF]; 91 | uint32_t sextet_d = base64[i] == '=' ? 0 & i++ : m_decodingTable[(int)base64[i++]&0xFF]; 92 | 93 | uint32_t triple = (sextet_a << 3 * 6) 94 | + (sextet_b << 2 * 6) 95 | + (sextet_c << 1 * 6) 96 | + (sextet_d << 0 * 6); 97 | 98 | if (j < *resultLength) decodedData[j++] = (triple >> 2 * 8) & 0xFF; 99 | if (j < *resultLength) decodedData[j++] = (triple >> 1 * 8) & 0xFF; 100 | if (j < *resultLength) decodedData[j++] = (triple >> 0 * 8) & 0xFF; 101 | } 102 | 103 | return decodedData; 104 | } 105 | 106 | 107 | void Base64::build_decoding_table() { 108 | 109 | m_decodingTable = new char[256]; 110 | 111 | for (int i = 0; i < 256; i++) 112 | m_decodingTable[(int)m_encodingTable[i]] = i; 113 | } 114 | -------------------------------------------------------------------------------- /Base64.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // Base64.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 05/04/13. 20 | // 21 | 22 | #ifndef __FireBreath__Base64__ 23 | #define __FireBreath__Base64__ 24 | 25 | #include 26 | 27 | class Base64 { 28 | public: 29 | static char *decode(std::string base64, int *resultLength); 30 | static std::string encode(unsigned char *buffer, int length); 31 | 32 | private: 33 | static char m_encodingTable[]; 34 | static char *m_decodingTable; 35 | static int m_modTable[]; 36 | 37 | static void build_decoding_table(); 38 | 39 | 40 | }; 41 | 42 | #endif /* defined(__FireBreath__Base64__) */ 43 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # 3 | # Auto-generated CMakeLists.txt for the Web Crypto Key and Certificate Discovery project 4 | # 5 | #\**********************************************************/ 6 | 7 | # Written to work with cmake 2.6 8 | cmake_minimum_required (VERSION 2.6) 9 | set (CMAKE_BACKWARDS_COMPATIBILITY 2.6) 10 | 11 | Project(${PLUGIN_NAME}) 12 | 13 | file (GLOB GENERAL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 14 | [^.]*.cpp 15 | [^.]*.h 16 | [^.]*.cmake 17 | ) 18 | 19 | include_directories(${PLUGIN_INCLUDE_DIRS}) 20 | 21 | # Generated files are stored in ${GENERATED} by the project configuration 22 | SET_SOURCE_FILES_PROPERTIES( 23 | ${GENERATED} 24 | PROPERTIES 25 | GENERATED 1 26 | ) 27 | 28 | SOURCE_GROUP(Generated FILES 29 | ${GENERATED} 30 | ) 31 | 32 | SET( SOURCES 33 | ${GENERAL} 34 | ${GENERATED} 35 | ) 36 | 37 | # This will include Win/projectDef.cmake, X11/projectDef.cmake, Mac/projectDef 38 | # depending on the platform 39 | include_platform() 40 | 41 | #this will build a Chrome package 42 | #add_chrome_package(${PLUGIN_NAME} 43 | # ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/ 44 | # "${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${FBSTRING_PluginFileName}.dll" 45 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/package_key.pem" 46 | # ${PROJECT_NAME}) 47 | 48 | #this will build a XPI package using XPISigner (see http://code.google.com/p/xpisigner/ ) 49 | # add_signed_xpi_installer(${PLUGIN_NAME} 50 | # ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/ 51 | # "${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${FBSTRING_PluginFileName}.dll" 52 | # $ENV{XPI_PATH} 53 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 54 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 55 | # ${PROJECT_NAME}) 56 | 57 | -------------------------------------------------------------------------------- /Chrome/chromepackage/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Web Crypto Key and Certificate Discovery", 3 | "version": "${FBSTRING_PLUGIN_VERSION}", 4 | "description": "This plug-in will add support for the Web Crypto Key and Certificate Discovery API to your browser.", 5 | 6 | "plugins": [ 7 | { "path": "npWebCryptoKeyandCertificateDiscovery.dll", "public": true } 8 | ] 9 | } -------------------------------------------------------------------------------- /CryptoOperation.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // CryptoOperation.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 29/03/13. 20 | // 21 | // 22 | 23 | #include "CryptoOperation.h" 24 | #include "JSEvent.h" 25 | 26 | #include "Base64.h" 27 | 28 | CryptoOperation::CryptoOperation(const FB::BrowserHostPtr& host, const boost::shared_ptr& key, const boost::shared_ptr& algorithm): m_host(host), m_key(key), m_algorithm(algorithm), m_finish(false), m_abort(false) 29 | { 30 | initializePropertiesAndMethods(); 31 | } 32 | 33 | 34 | void CryptoOperation::initializePropertiesAndMethods() 35 | { 36 | registerEvent("oncomplete"); 37 | registerEvent("onerror"); 38 | registerEvent("onprogress"); 39 | registerEvent("onabort"); 40 | 41 | registerProperty("result", make_property(this, &CryptoOperation::get_result)); 42 | registerProperty("key", make_property(this, &CryptoOperation::get_key)); 43 | registerProperty("algorithm", make_property(this, &CryptoOperation::get_algorithm)); 44 | 45 | registerMethod("process", make_method(this, &CryptoOperation::process)); 46 | registerMethod("finish", make_method(this, &CryptoOperation::finish)); 47 | registerMethod("abort", make_method(this, &CryptoOperation::abort)); 48 | 49 | } 50 | 51 | 52 | boost::shared_ptr CryptoOperation::get_key() 53 | { 54 | return m_key; 55 | } 56 | 57 | boost::shared_ptr CryptoOperation::get_algorithm() 58 | { 59 | return m_algorithm; 60 | } 61 | 62 | FB::variant CryptoOperation::get_result() 63 | { 64 | return m_result; 65 | } 66 | 67 | void CryptoOperation::set_result(FB::variant result) 68 | { 69 | m_result = result; 70 | } 71 | 72 | void CryptoOperation::process(const std::string& bufferBase64) 73 | { 74 | if (m_thread.get_id() == boost::thread::id()) 75 | { 76 | m_thread = boost::thread(&CryptoOperation::processQueue, this); 77 | } 78 | 79 | { 80 | boost::lock_guard lock(m_mut); 81 | m_processQueue.push(bufferBase64); 82 | } 83 | m_cond.notify_one(); 84 | } 85 | 86 | void CryptoOperation::finish() 87 | { 88 | { 89 | boost::lock_guard lock(m_mut); 90 | m_finish = true; 91 | } 92 | m_cond.notify_one(); 93 | } 94 | 95 | void CryptoOperation::abort() 96 | { 97 | { 98 | boost::lock_guard lock(m_mut); 99 | m_abort = true; 100 | } 101 | m_cond.notify_one(); 102 | } 103 | 104 | void CryptoOperation::processQueue() 105 | { 106 | { 107 | boost::unique_lock lock(m_mut); 108 | while (!m_processQueue.empty() || !m_finish) 109 | { 110 | while(m_processQueue.empty() && !m_finish && !m_abort) 111 | { 112 | m_cond.wait(lock); 113 | } 114 | 115 | if (m_abort) 116 | { 117 | break; 118 | } 119 | 120 | if (!m_processQueue.empty()) 121 | { 122 | std::string dataBase64 = m_processQueue.front(); 123 | m_processQueue.pop(); 124 | lock.unlock(); 125 | int length; 126 | char* data = Base64::decode(dataBase64, &length); 127 | processImpl(data, length); 128 | delete[] data; 129 | lock.lock(); 130 | } 131 | } 132 | } 133 | 134 | if (m_abort) 135 | { 136 | FireJSEvent("onabort", FB::VariantMap(), FB::variant_list_of()); 137 | return; 138 | } 139 | 140 | if (m_finish) 141 | { 142 | finishImpl(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /CryptoOperation.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // CryptoOperation.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 29/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__CryptoOperation__ 24 | #define __FireBreath__CryptoOperation__ 25 | 26 | #include "JSAPIAuto.h" 27 | #include "BrowserHost.h" 28 | #include 29 | #include 30 | #include 31 | 32 | #include "Algorithm.h" 33 | #include "Key.h" 34 | 35 | class CryptoOperation : public FB::JSAPIAuto 36 | { 37 | public: 38 | CryptoOperation(const FB::BrowserHostPtr& host, const boost::shared_ptr& key, const boost::shared_ptr& algorithm); 39 | 40 | virtual ~CryptoOperation() {}; 41 | 42 | void process(const std::string& bufferBase64); 43 | 44 | void finish(); 45 | 46 | void abort(); 47 | 48 | boost::shared_ptr get_key(); 49 | boost::shared_ptr get_algorithm(); 50 | 51 | void set_result(FB::variant result); 52 | FB::variant get_result(); 53 | 54 | 55 | protected: 56 | virtual void processImpl(const char *buffer, unsigned long size) = 0; 57 | virtual void finishImpl() = 0; 58 | 59 | protected: 60 | FB::BrowserHostPtr m_host; 61 | 62 | private: 63 | boost::shared_ptr m_key; 64 | boost::shared_ptr m_algorithm; 65 | FB::variant m_result; 66 | 67 | std::queue m_processQueue; 68 | bool m_finish, m_abort; 69 | 70 | boost::thread m_thread; 71 | boost::condition_variable m_cond; 72 | boost::mutex m_mut; 73 | 74 | void initializePropertiesAndMethods(); 75 | void processQueue(); 76 | }; 77 | 78 | #endif /* defined(__FireBreath__CryptoOperation__) */ 79 | -------------------------------------------------------------------------------- /Factory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated Factory.cpp 18 | 19 | This file contains the auto-generated factory methods 20 | for the WebCryptoKeyandCertificateDiscovery project 21 | 22 | \**********************************************************/ 23 | 24 | #include "FactoryBase.h" 25 | #include "WebCryptoKeyandCertificateDiscovery.h" 26 | #include 27 | 28 | class PluginFactory : public FB::FactoryBase 29 | { 30 | public: 31 | /////////////////////////////////////////////////////////////////////////////// 32 | /// @fn FB::PluginCorePtr createPlugin(const std::string& mimetype) 33 | /// 34 | /// @brief Creates a plugin object matching the provided mimetype 35 | /// If mimetype is empty, returns the default plugin 36 | /////////////////////////////////////////////////////////////////////////////// 37 | FB::PluginCorePtr createPlugin(const std::string& mimetype) 38 | { 39 | return boost::make_shared(); 40 | } 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | /// @see FB::FactoryBase::globalPluginInitialize 44 | /////////////////////////////////////////////////////////////////////////////// 45 | void globalPluginInitialize() 46 | { 47 | WebCryptoKeyandCertificateDiscovery::StaticInitialize(); 48 | } 49 | 50 | /////////////////////////////////////////////////////////////////////////////// 51 | /// @see FB::FactoryBase::globalPluginDeinitialize 52 | /////////////////////////////////////////////////////////////////////////////// 53 | void globalPluginDeinitialize() 54 | { 55 | WebCryptoKeyandCertificateDiscovery::StaticDeinitialize(); 56 | } 57 | }; 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | /// @fn getFactoryInstance() 61 | /// 62 | /// @brief Returns the factory instance for this plugin module 63 | /////////////////////////////////////////////////////////////////////////////// 64 | FB::FactoryBasePtr getFactoryInstance() 65 | { 66 | static boost::shared_ptr factory = boost::make_shared(); 67 | return factory; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /Key.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // Key.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 29/03/13. 20 | // 21 | // 22 | 23 | #include "Key.h" 24 | 25 | Key::Key(const FB::BrowserHostPtr& host, std::string type, bool extractable, Algorithm algorithm, FB::VariantList keyUsage) : JSAPIAuto("Key"), m_host(host), m_type(type), m_extractable(extractable), m_algorithm(algorithm), m_keyUsage(keyUsage) 26 | { 27 | initializeProperties(); 28 | } 29 | 30 | Key::Key(const Key&other) : JSAPIAuto("Key"), m_host(other.m_host), m_type(other.m_type), m_extractable(other.m_extractable), m_algorithm(other.m_algorithm), m_keyUsage(other.m_keyUsage) 31 | { 32 | initializeProperties(); 33 | } 34 | 35 | Key& Key::operator=(const Key& other) 36 | { 37 | m_host = other.m_host; 38 | m_type = other.m_type; 39 | m_extractable = other.m_extractable; 40 | m_algorithm = other.m_algorithm; 41 | m_keyUsage = other.m_keyUsage; 42 | 43 | initializeProperties(); 44 | 45 | return *this; 46 | } 47 | 48 | std::string Key::get_type() 49 | { 50 | return m_type; 51 | } 52 | 53 | bool Key::get_extractable() 54 | { 55 | return m_extractable; 56 | } 57 | 58 | FB::JSAPIPtr Key::get_algorithm() 59 | { 60 | return boost::shared_ptr(new Algorithm(m_algorithm)); 61 | } 62 | 63 | FB::VariantList Key::get_keyUsage() 64 | { 65 | return m_keyUsage; 66 | } 67 | 68 | void Key::initializeProperties() 69 | { 70 | registerProperty("type", make_property(this, &Key::get_type)); 71 | registerProperty("extractable", make_property(this, &Key::get_extractable)); 72 | registerProperty("algorithm", make_property(this, &Key::get_algorithm)); 73 | registerProperty("keyUsage", make_property(this, &Key::get_keyUsage)); 74 | } 75 | -------------------------------------------------------------------------------- /Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // Key.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 29/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__Key__ 24 | #define __FireBreath__Key__ 25 | 26 | #include 27 | 28 | #include "JSAPIAuto.h" 29 | #include "BrowserHost.h" 30 | #include "Algorithm.h" 31 | 32 | 33 | class Key : public FB::JSAPIAuto 34 | { 35 | public: 36 | Key(const FB::BrowserHostPtr& host, std::string type, bool extractable, Algorithm algorithm, FB::VariantList keyUsage); 37 | virtual ~Key() {}; 38 | 39 | Key(const Key& other); 40 | Key& operator=(const Key& other); 41 | 42 | std::string get_type(); 43 | bool get_extractable(); 44 | FB::JSAPIPtr get_algorithm(); 45 | FB::VariantList get_keyUsage(); 46 | 47 | protected: 48 | FB::BrowserHostPtr m_host; 49 | 50 | private: 51 | void initializeProperties(); 52 | 53 | private: 54 | std::string m_type; 55 | bool m_extractable; 56 | Algorithm m_algorithm; 57 | FB::VariantList m_keyUsage; 58 | }; 59 | 60 | #endif /* defined(__FireBreath__Key__) */ 61 | -------------------------------------------------------------------------------- /KeyOperation.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // KeyOperation.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 22/03/13. 20 | // 21 | // 22 | 23 | #include "KeyOperation.h" 24 | #include "JSEvent.h" 25 | 26 | // if (m_callback) // if not NULL 27 | // m_callback->InvokeAsync("", FB::variant_list_of(a)("Param2")(3)); 28 | 29 | KeyOperation::KeyOperation(const FB::BrowserHostPtr& host): m_host(host) 30 | { 31 | initializeProperties(); 32 | } 33 | 34 | 35 | void KeyOperation::initializeProperties() 36 | { 37 | registerProperty("result", make_property(this, &KeyOperation::get_result)); 38 | 39 | registerEvent("oncomplete"); 40 | registerEvent("onerror"); 41 | } 42 | 43 | FB::variant KeyOperation::get_result() { 44 | return m_result; 45 | } 46 | 47 | void KeyOperation::set_result(FB::variant result) { 48 | m_result = result; 49 | } 50 | -------------------------------------------------------------------------------- /KeyOperation.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // KeyOperation.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 22/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__KeyOperation__ 24 | #define __FireBreath__KeyOperation__ 25 | 26 | #include "JSAPIAuto.h" 27 | #include "BrowserHost.h" 28 | 29 | class KeyOperation : public FB::JSAPIAuto 30 | { 31 | public: 32 | KeyOperation(const FB::BrowserHostPtr& host); 33 | 34 | virtual ~KeyOperation() {}; 35 | 36 | void set_result(FB::variant result); 37 | FB::variant get_result(); 38 | 39 | 40 | protected: 41 | FB::BrowserHostPtr m_host; 42 | 43 | private: 44 | FB::variant m_result; 45 | 46 | void initializeProperties(); 47 | }; 48 | 49 | #endif /* defined(__FireBreath__KeyOperation__) */ 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2013 Inventive Designers 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Mac/CryptoOperationImpl.cpp: -------------------------------------------------------------------------------- 1 | // You may obtain a copy of the License at 2 | // 3 | // http://www.apache.org/licenses/LICENSE-2.0 4 | // 5 | // Unless required by applicable law or agreed to in writing, software 6 | // distributed under the License is distributed on an "AS IS" BASIS, 7 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 8 | // See the License for the specific language governing permissions and 9 | // limitations under the License. 10 | 11 | // 12 | // CryptoOperationImpl.cpp 13 | // FireBreath 14 | // 15 | // Created by Nick Van den Bleeken on 03/04/13. 16 | // 17 | // 18 | 19 | #include "CryptoOperationImpl.h" 20 | #include "KeyImpl.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | CryptoOperationImpl::~CryptoOperationImpl() 27 | { 28 | if (m_signingTransform) 29 | { 30 | CFRelease(m_signingTransform); 31 | m_signingTransform = NULL; 32 | } 33 | } 34 | 35 | 36 | void CryptoOperationImpl::processImpl(const char *buffer, unsigned long size) 37 | { 38 | initialize(); 39 | 40 | CFErrorRef error = NULL; 41 | CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, (UInt8*)buffer, size); 42 | 43 | //TODO doesn't seems to work, it looks like only the first kSecTransformInputAttributeName is used. 44 | 45 | SecTransformSetAttribute(m_signingTransform, 46 | kSecTransformInputAttributeName, dataRef, &error); 47 | 48 | if (NULL != error) 49 | { 50 | CFRelease(m_signingTransform); 51 | m_signingTransform = NULL; 52 | FireJSEvent("onabort", FB::VariantMap(), FB::variant_list_of()); 53 | } 54 | } 55 | 56 | void CryptoOperationImpl::finishImpl() 57 | { 58 | CFErrorRef error = NULL; 59 | CFDataRef signature = (CFDataRef)SecTransformExecute(m_signingTransform, &error); 60 | 61 | if (NULL != error) 62 | { 63 | FireJSEvent("onabort", FB::VariantMap(), FB::variant_list_of()); 64 | return; 65 | } 66 | 67 | CFIndex length = CFDataGetLength(signature); 68 | const UInt8 *signatureBytes = CFDataGetBytePtr(signature); 69 | 70 | std::vector result((unsigned char*)signatureBytes, ((unsigned char*)signatureBytes) + length); 71 | 72 | set_result(result); 73 | 74 | CFRelease(signature); 75 | CFRelease(m_signingTransform); 76 | m_signingTransform = NULL; 77 | 78 | if (NULL != error) 79 | { 80 | FireJSEvent("onabort", FB::VariantMap(), FB::variant_list_of()); 81 | return; 82 | } 83 | 84 | FireJSEvent("oncomplete", FB::VariantMap(), FB::variant_list_of()); 85 | } 86 | 87 | 88 | SecKeyRef CryptoOperationImpl::getKeyRef() 89 | { 90 | return ((KeyImpl&)*get_key()).getKey(); 91 | } 92 | 93 | void CryptoOperationImpl::initialize() 94 | { 95 | if (m_signingTransform) 96 | { 97 | // We have already initialized the signing transform 98 | return; 99 | } 100 | 101 | m_signingTransform = SecSignTransformCreate(getKeyRef(), NULL); 102 | SecTransformSetAttribute(m_signingTransform, kSecInputIsDigest, kCFBooleanTrue, NULL); 103 | SecTransformSetAttribute(m_signingTransform, kSecDigestTypeAttribute, kSecDigestSHA1, NULL); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /Mac/CryptoOperationImpl.h: -------------------------------------------------------------------------------- 1 | // You may obtain a copy of the License at 2 | // 3 | // http://www.apache.org/licenses/LICENSE-2.0 4 | // 5 | // Unless required by applicable law or agreed to in writing, software 6 | // distributed under the License is distributed on an "AS IS" BASIS, 7 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 8 | // See the License for the specific language governing permissions and 9 | // limitations under the License. 10 | 11 | // 12 | // CryptoOperationImpl.h 13 | // FireBreath 14 | // 15 | // Created by Nick Van den Bleeken on 03/04/13. 16 | // 17 | // 18 | 19 | #ifndef __FireBreath__CryptoOperationImpl__ 20 | #define __FireBreath__CryptoOperationImpl__ 21 | 22 | #include "../CryptoOperation.h" 23 | #include 24 | 25 | class CryptoOperationImpl : public CryptoOperation 26 | { 27 | public: 28 | CryptoOperationImpl(const FB::BrowserHostPtr& host, const boost::shared_ptr& key, const boost::shared_ptr& algorithm) : CryptoOperation(host, key, algorithm), m_signingTransform(NULL) { } 29 | 30 | virtual ~CryptoOperationImpl(); 31 | 32 | 33 | 34 | protected: 35 | void processImpl(const char *buffer, unsigned long size); 36 | void finishImpl(); 37 | 38 | private: 39 | 40 | SecKeyRef getKeyRef(); 41 | void initialize(); 42 | 43 | private: 44 | SecTransformRef m_signingTransform; 45 | }; 46 | 47 | #endif /* defined(__FireBreath__CryptoOperationImpl__) */ 48 | -------------------------------------------------------------------------------- /Mac/KeyImpl.cpp: -------------------------------------------------------------------------------- 1 | // You may obtain a copy of the License at 2 | // 3 | // http://www.apache.org/licenses/LICENSE-2.0 4 | // 5 | // Unless required by applicable law or agreed to in writing, software 6 | // distributed under the License is distributed on an "AS IS" BASIS, 7 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 8 | // See the License for the specific language governing permissions and 9 | // limitations under the License. 10 | 11 | // 12 | // KeyImpl.cpp 13 | // FireBreath 14 | // 15 | // Created by Nick Van den Bleeken on 03/04/13. 16 | // 17 | // 18 | 19 | #include "KeyImpl.h" 20 | -------------------------------------------------------------------------------- /Mac/KeyImpl.h: -------------------------------------------------------------------------------- 1 | // You may obtain a copy of the License at 2 | // 3 | // http://www.apache.org/licenses/LICENSE-2.0 4 | // 5 | // Unless required by applicable law or agreed to in writing, software 6 | // distributed under the License is distributed on an "AS IS" BASIS, 7 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 8 | // See the License for the specific language governing permissions and 9 | // limitations under the License. 10 | 11 | // 12 | // KeyImpl.h 13 | // FireBreath 14 | // 15 | // Created by Nick Van den Bleeken on 03/04/13. 16 | // 17 | // 18 | 19 | #ifndef __FireBreath__KeyImpl__ 20 | #define __FireBreath__KeyImpl__ 21 | 22 | #include "../Key.h" 23 | 24 | #include 25 | 26 | class KeyImpl : public Key 27 | { 28 | public: 29 | KeyImpl(const FB::BrowserHostPtr& host, std::string type, bool extractable, Algorithm algorithm, FB::VariantList keyUsage, const boost::shared_ptr& key) : Key(host, type, extractable, algorithm, keyUsage), m_key(key) {} 30 | virtual ~KeyImpl() {} 31 | 32 | KeyImpl(const KeyImpl& other) : Key(other), m_key(other.m_key) {} 33 | KeyImpl& operator=(const KeyImpl& other) { Key::operator=(other); m_key = other.m_key; return *this;} 34 | 35 | SecKeyRef getKey() { return *m_key;} 36 | 37 | private: 38 | boost::shared_ptr m_key; 39 | }; 40 | 41 | 42 | #endif /* defined(__FireBreath__KeyImpl__) */ 43 | -------------------------------------------------------------------------------- /Mac/MacUtils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // MacUtils.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #include "MacUtils.h" 24 | 25 | 26 | std::string MacUtils::CFStringRefToStringUsingUTF8String(CFStringRef aString) 27 | { 28 | if (aString == NULL) { 29 | return ""; 30 | } 31 | 32 | CFIndex length = CFStringGetLength(aString); 33 | CFIndex maxSize = 34 | CFStringGetMaximumSizeForEncoding(length, 35 | kCFStringEncodingUTF8); 36 | char *buffer = (char *)malloc(maxSize); 37 | if (CFStringGetCString(aString, buffer, maxSize, 38 | kCFStringEncodingUTF8)) { 39 | std::string result = std::string(buffer); 40 | free(buffer); 41 | return result; 42 | } 43 | return ""; 44 | } 45 | 46 | std::wstring MacUtils::CFStringRefToWString(CFStringRef aString) 47 | { 48 | if (aString == NULL) { 49 | return L""; 50 | } 51 | 52 | if (!aString) 53 | return false; 54 | CFDataRef cfData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, 55 | aString, kCFStringEncodingUTF32, 0); 56 | CFRelease(aString); 57 | if (!cfData) 58 | return false; 59 | int out_byte_len = CFDataGetLength(cfData); 60 | out_byte_len -= sizeof(wchar_t); // don't count the 32 bit BOM char at start 61 | int out_len = out_byte_len / sizeof(wchar_t); 62 | wchar_t *tmp = new wchar_t[out_len + 1]; 63 | // start after the BOM, hence sizeof(wchar_t) 64 | CFDataGetBytes(cfData, CFRangeMake(sizeof(wchar_t), out_byte_len), 65 | (UInt8*)tmp); 66 | CFRelease(cfData); 67 | tmp[out_len] = 0; 68 | std::wstring result = tmp; 69 | delete[] tmp; 70 | 71 | return result; 72 | } -------------------------------------------------------------------------------- /Mac/MacUtils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // MacUtils.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__MacUtils__ 24 | #define __FireBreath__MacUtils__ 25 | 26 | #include 27 | #include 28 | 29 | 30 | class MacUtils 31 | { 32 | public: 33 | static std::string CFStringRefToStringUsingUTF8String(CFStringRef aString); 34 | static std::wstring CFStringRefToWString(CFStringRef aString); 35 | }; 36 | 37 | 38 | #endif /* defined(__FireBreath__MacUtils__) */ 39 | -------------------------------------------------------------------------------- /Mac/WebCryptoKeyandCertificateDiscoveryAPI.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated WebCryptoKeyandCertificateDiscoveryAPI.cpp 18 | 19 | \**********************************************************/ 20 | 21 | #include "JSObject.h" 22 | #include "variant_list.h" 23 | #include "DOM/Document.h" 24 | #include "global/config.h" 25 | 26 | #include "../WebCryptoKeyandCertificateDiscoveryAPI.h" 27 | #include "CryptoOperationImpl.h" 28 | 29 | 30 | boost::shared_ptr WebCryptoKeyandCertificateDiscoveryAPI::encrypt(boost::shared_ptr algorithm, boost::shared_ptr key, boost::optional base64Buffer) 31 | { 32 | boost::shared_ptr result = boost::shared_ptr(new CryptoOperationImpl(m_host, key, algorithm)); 33 | 34 | if (base64Buffer) 35 | { 36 | result->process(*base64Buffer); 37 | result->finish(); 38 | } 39 | 40 | return result; 41 | } 42 | -------------------------------------------------------------------------------- /Mac/X509CertificateMac.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateMac.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #include "X509CertificateMac.h" 24 | 25 | 26 | #include "MacUtils.h" 27 | #include "KeyImpl.h" 28 | 29 | #include 30 | 31 | static void X509CertificateMacReleaseCFTypeRef(SecKeyRef* pcf) 32 | { 33 | CFRelease(*pcf); 34 | delete pcf; 35 | } 36 | 37 | std::map X509CertificateMac::m_oid_to_str = X509CertificateMac::createOIDtoStringMapping(); 38 | 39 | X509CertificateMac::X509CertificateMac(const FB::BrowserHostPtr& host, SecCertificateRef cert_ref, boost::shared_ptr privateKey_ref, X500Principal issuerX500Principal, X500Principal subjectX500Principal, int version, std::string validityNotBefore, std::string validityNotAfter, std::string serialNumber) : X509Certificate(host, extractName(cert_ref)), m_cert_ref(cert_ref), m_privateKey_ref(privateKey_ref), m_version(version), m_validityNotBefore(validityNotBefore), m_validityNotAfter(validityNotAfter), m_serialNumber(serialNumber), m_issuerX500Principal(issuerX500Principal), m_subjectX500Principal(subjectX500Principal) 40 | { 41 | 42 | 43 | //MacUtils::CFStringRefToStringUsingUTF8String 44 | 45 | /* 46 | CFArrayRef values; 47 | CFDictionaryRef dict; 48 | dict = CFDictionaryGetValue(vals, kSecOIDBasicConstraints ); 49 | values = dict ? CFDictionaryGetValue(dict, kSecPropertyKeyValue) : NULL; 50 | if (values) { 51 | for(int i = 0; i < CFArrayGetCount(values); i++) { 52 | CFDictionaryRef subDict = CFArrayGetValueAtIndex(values, i); 53 | 54 | // We cannot find OID defines for the CA - so rely on the lower libraries to give us a string 55 | // of sorts. Not a good idea - as now this code can be foiled by a actual string. 56 | // 57 | NSString *k = [NSString stringWithFormat:@"%@", CFDictionaryGetValue(subDict, kSecPropertyKeyLabel)]; 58 | NSString *v = [NSString stringWithFormat:@"%@", CFDictionaryGetValue(subDict, kSecPropertyKeyValue)]; 59 | if ([@"Certificate Authority" isEqualToString:k] && [@"Yes" isEqualToString:v]) { 60 | isCA = TRUE; 61 | } 62 | } 63 | }; 64 | 65 | // Fall back on a simple self-sign check if there where no kSecOIDBasicConstraints. 66 | // set on the cert. Note that it is a DN is equal check - in some cases 67 | // doing a 509v3 Subject/Authority Key Identifier may be better ?? XXXX 68 | // 69 | if (!isCA && !values) { 70 | dict = CFDictionaryGetValue(vals, kSecOIDX509V1SubjectName); 71 | values = dict ? CFDictionaryGetValue(dict, kSecPropertyKeyValue) : NULL; 72 | subject = [NSString stringWithFormat:@"%@", values]; 73 | 74 | dict = CFDictionaryGetValue(vals, kSecOIDX509V1IssuerName); 75 | values = dict ? CFDictionaryGetValue(dict, kSecPropertyKeyValue) : NULL; 76 | issuer = [NSString stringWithFormat:@"%@", values]; 77 | 78 | // Crap way of secondgessing CA ness. 79 | if ([issuer isEqualToString:subject]) 80 | isCA = TRUE; 81 | }; 82 | 83 | SecPolicyRef policy = SecPolicyCreateBasicX509(); // SecPolicyCreateSSL(YES,nil); 84 | CFArrayRef chain = CFArrayCreate(NULL, (const void**)(&certificateRef), 1, NULL); 85 | 86 | SecTrustRef trustRef; 87 | SecTrustCreateWithCertificates(chain, policy, &trustRef); 88 | 89 | SecTrustResultType result; 90 | SecTrustEvaluate (trustRef, &result); 91 | 92 | if(result == kSecTrustResultProceed) { 93 | isUserTrust = TRUE; 94 | isInvalid = FALSE; 95 | } else 96 | if (result == kSecTrustResultUnspecified) 97 | isInvalid = FALSE; 98 | 99 | CFRelease(trustRef); 100 | CFRelease(chain);*/ 101 | } 102 | 103 | 104 | boost::shared_ptr X509CertificateMac::createX509CertificateMac(const FB::BrowserHostPtr& host, SecCertificateRef cert_ref, SecKeyRef privateKey) 105 | { 106 | const void *keys[] = { /*kSecOIDX509V1CertificateIssuerUniqueId, kSecOIDX509V1CertificateSubjectUniqueId, */kSecOIDX509V1IssuerName, /*kSecOIDX509V1IssuerNameLDAP, kSecOIDX509V1IssuerNameStd, */kSecOIDX509V1SerialNumber, kSecOIDX509V1Signature, /*kSecOIDX509V1SignatureAlgorithm, kSecOIDX509V1SignatureAlgorithmParameters, kSecOIDX509V1SignatureAlgorithmTBS, kSecOIDX509V1SignatureCStruct, kSecOIDX509V1SignatureStruct, */kSecOIDX509V1SubjectName, /*kSecOIDX509V1SubjectNameCStruct, kSecOIDX509V1SubjectNameLDAP, kSecOIDX509V1SubjectNameStd, */kSecOIDX509V1SubjectPublicKey, /*kSecOIDX509V1SubjectPublicKeyAlgorithm, kSecOIDX509V1SubjectPublicKeyAlgorithmParameters, kSecOIDX509V1SubjectPublicKeyCStruct, */kSecOIDX509V1ValidityNotAfter, kSecOIDX509V1ValidityNotBefore, kSecOIDX509V1Version/*, kSecOIDX509V3Certificate*/ }; 107 | CFArrayRef keySelection = CFArrayCreate(NULL, keys , sizeof(keys)/sizeof(keys[0]), &kCFTypeArrayCallBacks); 108 | CFDictionaryRef vals = SecCertificateCopyValues(cert_ref, keySelection, NULL); 109 | 110 | 111 | X500Principal issuerX500Principal = convertToX500Principal(host, (CFArrayRef)CFDictionaryGetValue((CFDictionaryRef)CFDictionaryGetValue(vals, kSecOIDX509V1IssuerName), kSecPropertyKeyValue)); 112 | X500Principal subjectX500Principal = convertToX500Principal(host, (CFArrayRef)CFDictionaryGetValue((CFDictionaryRef)CFDictionaryGetValue(vals, kSecOIDX509V1SubjectName), kSecPropertyKeyValue)); 113 | int version = CFStringGetIntValue((CFStringRef)CFDictionaryGetValue((CFDictionaryRef)CFDictionaryGetValue(vals, kSecOIDX509V1Version), kSecPropertyKeyValue)); 114 | std::string validityNotBefore = extractDateTime(vals, kSecOIDX509V1ValidityNotBefore); 115 | std::string validityNotAfter = extractDateTime(vals, kSecOIDX509V1ValidityNotAfter); 116 | std::string serialNumber = MacUtils::CFStringRefToStringUsingUTF8String((CFStringRef)CFDictionaryGetValue((CFDictionaryRef)CFDictionaryGetValue(vals, kSecOIDX509V1SerialNumber), kSecPropertyKeyValue)); 117 | 118 | return boost::shared_ptr(new X509CertificateMac(host, cert_ref, boost::shared_ptr(new SecKeyRef(privateKey), std::ptr_fun(X509CertificateMacReleaseCFTypeRef)), issuerX500Principal, subjectX500Principal, version, validityNotBefore, validityNotAfter, serialNumber)); 119 | } 120 | 121 | 122 | FB::JSAPIPtr X509CertificateMac::get_issuerX500Principal() 123 | { 124 | return boost::shared_ptr(new X500Principal(m_issuerX500Principal)); 125 | } 126 | 127 | FB::FBDateString X509CertificateMac::get_notAfter() 128 | { 129 | return m_validityNotAfter; 130 | } 131 | 132 | FB::FBDateString X509CertificateMac::get_notBefore() 133 | { 134 | return m_validityNotBefore; 135 | } 136 | 137 | FB::JSAPIPtr X509CertificateMac::get_privateKey() 138 | { 139 | // TODO fill in parameters 140 | return boost::shared_ptr(new KeyImpl(m_host, "private", false, Algorithm(m_host, "Boe", FB::VariantMap()), FB::VariantList(), m_privateKey_ref)); 141 | } 142 | 143 | 144 | std::string X509CertificateMac::get_serialNumber() 145 | { 146 | return m_serialNumber; 147 | } 148 | 149 | 150 | FB::JSAPIPtr X509CertificateMac::get_subjectX500Principal() 151 | { 152 | return boost::shared_ptr(new X500Principal(m_subjectX500Principal)); 153 | } 154 | 155 | 156 | long X509CertificateMac::get_version() 157 | { 158 | return m_version; 159 | } 160 | 161 | 162 | FB::VariantList X509CertificateMac::get_keyUsage() 163 | { 164 | // TODO implement 165 | return FB::VariantList(); 166 | } 167 | 168 | std::string X509CertificateMac::extractName(SecCertificateRef cert_ref) 169 | { 170 | CFStringRef commonName = NULL; 171 | SecCertificateCopyCommonName(cert_ref, &commonName); 172 | std::string result = MacUtils::CFStringRefToStringUsingUTF8String(commonName); 173 | 174 | return result; 175 | } 176 | 177 | std::string X509CertificateMac::extractDateTime(CFDictionaryRef vals, CFTypeRef dateTimeRef) 178 | { 179 | CFNumberRef validityNotBeforeRef = (CFNumberRef)CFDictionaryGetValue((CFDictionaryRef)CFDictionaryGetValue(vals, dateTimeRef), kSecPropertyKeyValue); 180 | CFAbsoluteTime validityNotBefore; 181 | CFNumberGetValue(validityNotBeforeRef, kCFNumberDoubleType, &validityNotBefore); 182 | 183 | static CFTimeZoneRef zoneSystem = CFTimeZoneCopySystem(); 184 | CFGregorianDate validityNotBeforeGregorianDate = CFAbsoluteTimeGetGregorianDate(validityNotBefore, zoneSystem); 185 | 186 | char buffer [25]; 187 | sprintf(buffer, "%u-%02u-%02uT%02u:%02u:%02.2f", validityNotBeforeGregorianDate.year, validityNotBeforeGregorianDate.month, validityNotBeforeGregorianDate.day, validityNotBeforeGregorianDate.hour, validityNotBeforeGregorianDate.minute, validityNotBeforeGregorianDate.second); 188 | 189 | return buffer; 190 | } 191 | 192 | X500Principal X509CertificateMac::convertToX500Principal(const FB::BrowserHostPtr& host, CFArrayRef x500PrincipalRef) 193 | { 194 | std::wstringstream wss; 195 | 196 | CFIndex count = CFArrayGetCount(x500PrincipalRef); 197 | for (CFIndex idx = 0; idx < count; ++idx) 198 | { 199 | if (idx != 0) 200 | { 201 | wss << L", "; 202 | } 203 | CFDictionaryRef entry = (CFDictionaryRef)CFArrayGetValueAtIndex(x500PrincipalRef, idx); 204 | std::wstring oid = MacUtils::CFStringRefToWString((CFStringRef)CFDictionaryGetValue(entry, kSecPropertyKeyLabel)); 205 | std::wstring value = MacUtils::CFStringRefToWString((CFStringRef)CFDictionaryGetValue(entry, kSecPropertyKeyValue)); 206 | 207 | std::map::iterator it = m_oid_to_str.find(oid); 208 | if (it != m_oid_to_str.end()) 209 | { 210 | wss << it->second; 211 | } 212 | else 213 | { 214 | wss << oid; 215 | } 216 | wss << L"=" << value; 217 | } 218 | 219 | return X500Principal(host, wss.str()); 220 | } 221 | 222 | std::map X509CertificateMac::createOIDtoStringMapping() 223 | { 224 | std::map mapping; 225 | 226 | m_oid_to_str[L"2.5.4.3"] = L"CN"; 227 | m_oid_to_str[L"2.5.4.7"] = L"L"; 228 | m_oid_to_str[L"2.5.4.8"] = L"ST"; 229 | m_oid_to_str[L"2.5.4.10"] = L"O"; 230 | m_oid_to_str[L"2.5.4.11"] = L"OU"; 231 | m_oid_to_str[L"2.5.4.6"] = L"C"; 232 | m_oid_to_str[L"2.5.4.9"] = L"STREET"; 233 | 234 | // Extra fields from RFC 2253 235 | m_oid_to_str[L"0.9.2342.19200300.100.1.25"] = L"DC"; 236 | m_oid_to_str[L"0.9.2342.19200300.100.1.1"] = L"UID"; 237 | 238 | //m_oid_to_str[L"2.5.4.5"] = L"SERIALNUMBER"; 239 | 240 | return mapping; 241 | } 242 | -------------------------------------------------------------------------------- /Mac/X509CertificateMac.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateMac.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__X509CertificateMac__ 24 | #define __FireBreath__X509CertificateMac__ 25 | 26 | #include "../X509Certificate.h" 27 | 28 | #include "../X500Principal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | 36 | class X509CertificateMac: public X509Certificate 37 | { 38 | public: 39 | X509CertificateMac(const FB::BrowserHostPtr& host, SecCertificateRef cert_ref, boost::shared_ptr privateKey_ref,X500Principal issuerX500Principal, X500Principal subjectX500Principal, int version, std::string validityNotBefore, std::string validityNotAfter, std::string serialNumber); 40 | virtual ~X509CertificateMac() { CFRelease(m_cert_ref); }; 41 | 42 | static boost::shared_ptr createX509CertificateMac(const FB::BrowserHostPtr& host, SecCertificateRef cert_ref, SecKeyRef privateKeyRef); 43 | 44 | virtual FB::JSAPIPtr get_issuerX500Principal(); 45 | virtual FB::FBDateString get_notAfter(); 46 | virtual FB::FBDateString get_notBefore(); 47 | virtual FB::JSAPIPtr get_privateKey(); 48 | virtual std::string get_serialNumber(); 49 | virtual FB::JSAPIPtr get_subjectX500Principal(); 50 | virtual long get_version(); 51 | virtual FB::VariantList get_keyUsage(); // See rfc5280 for more information 52 | 53 | private: 54 | SecCertificateRef m_cert_ref; 55 | boost::shared_ptr m_privateKey_ref; 56 | 57 | long m_version; 58 | std::string m_validityNotBefore; 59 | std::string m_validityNotAfter; 60 | std::string m_serialNumber; 61 | X500Principal m_issuerX500Principal; 62 | X500Principal m_subjectX500Principal; 63 | 64 | static std::map m_oid_to_str; 65 | 66 | // Helper methods 67 | static std::string extractName(SecCertificateRef cert_ref); 68 | static std::string extractDateTime(CFDictionaryRef vals, CFTypeRef dateTimeRef); 69 | static X500Principal convertToX500Principal(const FB::BrowserHostPtr& host, CFArrayRef x500PrincipalRef); 70 | 71 | static std::map< std::wstring, std::wstring > createOIDtoStringMapping(); 72 | 73 | static void releaseCFTypeRef(CFTypeRef* cf); 74 | }; 75 | 76 | #endif /* defined(__FireBreath__X509CertificateMac__) */ 77 | -------------------------------------------------------------------------------- /Mac/X509CertificateSelectorWorkerFunc.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "../X509CertificateSelector.h" 20 | #include "X509CertificateMac.h" 21 | 22 | void X509CertificateSelectorWorkerFunc(X509CertificateSelector * selector) 23 | { 24 | CFArrayRef identities_ref = NULL; 25 | const void *keys[] = { kSecClass, kSecReturnRef, kSecMatchLimit }; 26 | const void *values[] = { kSecClassIdentity, kCFBooleanTrue, kSecMatchLimitAll }; // TODO we should list all certificates, but I can't find how to go back from a certificate to a private key 27 | CFDictionaryRef dict = CFDictionaryCreate(NULL, keys, values, sizeof(keys) / sizeof(*keys), NULL, NULL); 28 | OSStatus status = SecItemCopyMatching(dict, (CFTypeRef*) &identities_ref); 29 | 30 | if (status == noErr) 31 | { 32 | FB::VariantList result; 33 | for (CFIndex i = 0; i < CFArrayGetCount(identities_ref); ++i) { 34 | SecIdentityRef identity_ref = (SecIdentityRef)CFArrayGetValueAtIndex(identities_ref, i); 35 | 36 | SecCertificateRef cert_ref; 37 | SecIdentityCopyCertificate(identity_ref, &cert_ref); 38 | 39 | SecKeyRef privateKeyRef; 40 | SecIdentityCopyPrivateKey(identity_ref, &privateKeyRef); 41 | 42 | CSSM_CERT_TYPE certType = NULL; 43 | SecCertificateGetType(cert_ref, &certType); 44 | 45 | if (certType != CSSM_CERT_X_509v1 && certType != CSSM_CERT_X_509v2 && certType != CSSM_CERT_X_509v3) 46 | { 47 | continue; 48 | } 49 | 50 | result.push_back(make_variant(X509CertificateMac::createX509CertificateMac(selector->m_host, cert_ref, privateKeyRef))); 51 | } 52 | 53 | selector->set_result(result); 54 | selector->FireJSEvent("oncomplete", FB::VariantMap(), FB::variant_list_of()); 55 | } 56 | else 57 | { 58 | selector->FireJSEvent("onerror", FB::VariantMap(), FB::variant_list_of()); 59 | } 60 | 61 | if (dict) 62 | CFRelease(dict); 63 | } 64 | -------------------------------------------------------------------------------- /Mac/bundle_template/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${FBSTRING_PluginName} 9 | CFBundleGetInfoString 10 | ${FBSTRING_PluginName} ${FBSTRING_PLUGIN_VERSION}, ${FBSTRING_LegalCopyright} 11 | CFBundleIdentifier 12 | com.${FBTYPELIB_NAME}.${FBSTRING_PluginName} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundlePackageType 16 | BRPL 17 | CFBundleShortVersionString 18 | ${FBSTRING_PluginName} ${FBSTRING_PLUGIN_VERSION} 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${FBSTRING_PLUGIN_VERSION} 23 | CFPlugInDynamicRegisterFunction 24 | 25 | CFPlugInDynamicRegistration 26 | NO 27 | CFPlugInFactories 28 | 29 | 00000000-0000-0000-0000-000000000000 30 | MyFactoryFunction 31 | 32 | CFPlugInTypes 33 | 34 | 00000000-0000-0000-0000-000000000000 35 | 36 | 00000000-0000-0000-0000-000000000000 37 | 38 | 39 | CFPlugInUnloadFunction 40 | 41 | WebPluginName 42 | ${FBSTRING_ProductName} 43 | WebPluginDescription 44 | ${FBSTRING_PluginDescription} 45 | WebPluginMIMETypes 46 | 47 | @foreach (FBSTRING_MIMEType CUR_MIMETYPE FBSTRING_FileExtents CUR_EXTENT FBSTRING_PluginDescription CUR_DESC) 48 | ${CUR_MIMETYPE} 49 | 50 | WebPluginExtensions 51 | 52 | ${CUR_EXTENT} 53 | 54 | WebPluginTypeDescription 55 | ${CUR_DESC} 56 | 57 | @endforeach 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Mac/bundle_template/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | CFBundleName = "${FBSTRING_PluginName}.plugin"; 4 | NSHumanReadableCopyright = "${FBSTRING_LegalCopyright}"; 5 | -------------------------------------------------------------------------------- /Mac/bundle_template/Localized.r: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | resource 'STR#' (126) 4 | { { 5 | "${FBSTRING_LegalCopyright}", 6 | "${FBSTRING_ProductName}" 7 | } }; 8 | 9 | resource 'STR#' (127) 10 | { { 11 | "", 12 | } }; 13 | 14 | resource 'STR#' (128) 15 | { { 16 | @foreach (FBSTRING_MIMEType CUR_MIMETYPE FBSTRING_FileExtents CUR_EXTENT) 17 | "${CUR_MIMETYPE}", 18 | "${CUR_EXTENT}", 19 | @endforeach 20 | } }; 21 | -------------------------------------------------------------------------------- /Mac/dmg_template/.background/PLACE_BACKGROUND_PICTURE_HERE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InventiveDesigners/webcrypto-key-certificate-discovery-js/f9ddbbfa43935044f9208bffac751582c2fadaae/Mac/dmg_template/.background/PLACE_BACKGROUND_PICTURE_HERE.txt -------------------------------------------------------------------------------- /Mac/dmg_template/.background/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InventiveDesigners/webcrypto-key-certificate-discovery-js/f9ddbbfa43935044f9208bffac751582c2fadaae/Mac/dmg_template/.background/background.png -------------------------------------------------------------------------------- /Mac/dmg_template/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InventiveDesigners/webcrypto-key-certificate-discovery-js/f9ddbbfa43935044f9208bffac751582c2fadaae/Mac/dmg_template/README.txt -------------------------------------------------------------------------------- /Mac/dmgdesign.applescript: -------------------------------------------------------------------------------- 1 | on run args 2 | set thePluginName to (item 1 of args) 3 | set theInstallerName to (item 2 of args) 4 | tell application "Finder" 5 | tell disk theInstallerName 6 | open 7 | set current view of container window to icon view 8 | set toolbar visible of container window to false 9 | set statusbar visible of container window to false 10 | set the bounds of container window to {200, 100, 712, 612} 11 | set opts to the icon view options of container window 12 | set background picture of opts to file ".background:background.png" 13 | set arrangement of opts to not arranged 14 | set icon size of opts to 80 15 | set position of item thePluginName of container window to {150, 275} 16 | set position of item "Plugins" of container window to {650, 275} 17 | delay 5 18 | eject 19 | end tell 20 | end tell 21 | end run 22 | -------------------------------------------------------------------------------- /Mac/installer.cmake: -------------------------------------------------------------------------------- 1 | set(INSTALLER_NAME "${PLUGIN_NAME} Installer") 2 | 3 | FIREBREATH_FIND_COMMANDS() 4 | 5 | message(STATUS "Adding DMG installer for ${PROJECT_NAME}") 6 | add_custom_command( 7 | TARGET ${PROJECT_NAME} 8 | POST_BUILD 9 | COMMENT "------------ CREATE DMG INSTALLER" 10 | 11 | #replace the copy with svn/git/whatever export if needed 12 | COMMAND ${CMD_CP} -r ${CMAKE_CURRENT_SOURCE_DIR}/Mac/dmg_template ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template 13 | COMMAND ${CMD_CP} -R ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}.plugin ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template 14 | 15 | #Give an icon to your bundle 16 | #COMMAND ${CMD_SIPS} -i ${CMAKE_CURRENT_SOURCE_DIR}/Mac/icon.png 17 | #COMMAND ${CMD_DEREZ} -only icns ${CMAKE_CURRENT_SOURCE_DIR}/Mac/icon.png > ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/tempicns.rsrc 18 | #COMMAND ${CMD_REZ} -append ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/tempicns.rsrc -o `printf "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template/${PLUGIN_NAME}.plugin/Icon\r"` 19 | 20 | COMMAND ${CMD_SETFILE} -a C ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template/${PLUGIN_NAME}.plugin/ 21 | COMMAND ${CMD_LN} -s /Library/Internet\ Plug-Ins ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template/ 22 | COMMAND ${CMD_MV} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template/Internet\ Plug-Ins ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template/Plugins 23 | 24 | #Create the DMG 25 | COMMAND ${CMD_HDIUTIL} create -fs HFS+ -srcfolder ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template/ -volname "${INSTALLER_NAME}" -format UDRW ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}-temp.dmg 26 | COMMAND ${CMD_HDIUTIL} attach ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}-temp.dmg -noautoopen -quiet 27 | 28 | #Wait for the installer to mount 29 | COMMAND ${CMD_SLEEP} 2 30 | COMMAND ${CMD_OSASCRIPT} ${CMAKE_CURRENT_SOURCE_DIR}/Mac/dmgdesign.applescript ${PLUGIN_NAME}.plugin "${INSTALLER_NAME}" 31 | COMMAND ${CMD_SLEEP} 2 32 | COMMAND ${CMD_HDIUTIL} attach ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}-temp.dmg -noautoopen -quiet 33 | 34 | #Repeat the commands, as they are not always executed o_O 35 | COMMAND ${CMD_SLEEP} 2 36 | COMMAND ${CMD_OSASCRIPT} ${CMAKE_CURRENT_SOURCE_DIR}/Mac/dmgdesign.applescript ${PLUGIN_NAME}.plugin "${INSTALLER_NAME}" 37 | COMMAND ${CMD_SLEEP} 2 38 | 39 | COMMAND ${CMD_HDIUTIL} convert ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}-temp.dmg -format UDZO -imagekey zlib-level=9 -o ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}.dmg 40 | 41 | COMMAND ${CMD_RM} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}-temp.dmg 42 | COMMAND ${CMD_RM} -rf ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/dmg_template 43 | 44 | #COMMAND ${CMD_RM} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/tempicns.rsrc 45 | ) 46 | -------------------------------------------------------------------------------- /Mac/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated Mac project definition file for the 3 | # Web Crypto Key and Certificate Discovery project 4 | #\**********************************************************/ 5 | 6 | # Mac template platform definition CMake file 7 | # Included from ../CMakeLists.txt 8 | 9 | # remember that the current source dir is the project root; this file is in Mac/ 10 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | Mac/[^.]*.cpp 12 | Mac/[^.]*.h 13 | Mac/[^.]*.cmake 14 | ) 15 | 16 | # use this to add preprocessor definitions 17 | add_definitions( 18 | 19 | ) 20 | 21 | 22 | SOURCE_GROUP(Mac FILES ${PLATFORM}) 23 | 24 | set (SOURCES 25 | ${SOURCES} 26 | ${PLATFORM} 27 | ) 28 | 29 | set(PLIST "Mac/bundle_template/Info.plist") 30 | set(STRINGS "Mac/bundle_template/InfoPlist.strings") 31 | set(LOCALIZED "Mac/bundle_template/Localized.r") 32 | 33 | add_mac_plugin(${PROJECT_NAME} ${PLIST} ${STRINGS} ${LOCALIZED} SOURCES) 34 | 35 | FIND_LIBRARY(SECURITY_LIBRARY Security ) 36 | SET(EXTRA_LIBS ${SECURITY_LIBRARY}) 37 | 38 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 39 | target_link_libraries(${PROJECT_NAME} 40 | ${PLUGIN_INTERNAL_DEPS} 41 | ${EXTRA_LIBS} 42 | ) 43 | 44 | #To create a DMG, include the following file 45 | #include(Mac/installer.cmake) 46 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This product includes software developed at 2 | Inventive Designers (http://www.inventivedesigners.com) 3 | 4 | I. Included Third-Party Software 5 | - FireBreath (http://www.firebreath.org/) licensed under a dual license structure. FireBreath can be used under the New BSD license or the GNU Lesser General Public License v2.1 6 | 7 | II. Used Third-Party Software 8 | 9 | 10 | III. Overall License Summary 11 | - Apache License 2.0 12 | - New BSD or GNU Lesser General Public License v2.1 13 | -------------------------------------------------------------------------------- /PluginConfig.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # 3 | # Auto-Generated Plugin Configuration file 4 | # for Web Crypto Key and Certificate Discovery 5 | # 6 | #\**********************************************************/ 7 | 8 | set(PLUGIN_NAME "WebCryptoKeyandCertificateDiscovery") 9 | set(PLUGIN_PREFIX "WCKCD") 10 | set(COMPANY_NAME "InventiveDesigners") 11 | 12 | # ActiveX constants: 13 | set(FBTYPELIB_NAME WebCryptoKeyandCertificateDiscoveryLib) 14 | set(FBTYPELIB_DESC "WebCryptoKeyandCertificateDiscovery 1.0 Type Library") 15 | set(IFBControl_DESC "WebCryptoKeyandCertificateDiscovery Control Interface") 16 | set(FBControl_DESC "WebCryptoKeyandCertificateDiscovery Control Class") 17 | set(IFBComJavascriptObject_DESC "WebCryptoKeyandCertificateDiscovery IComJavascriptObject Interface") 18 | set(FBComJavascriptObject_DESC "WebCryptoKeyandCertificateDiscovery ComJavascriptObject Class") 19 | set(IFBComEventSource_DESC "WebCryptoKeyandCertificateDiscovery IFBComEventSource Interface") 20 | set(AXVERSION_NUM "1") 21 | 22 | # NOTE: THESE GUIDS *MUST* BE UNIQUE TO YOUR PLUGIN/ACTIVEX CONTROL! YES, ALL OF THEM! 23 | set(FBTYPELIB_GUID ef6f6862-7a76-5c3d-a3df-94582ae821ec) 24 | set(IFBControl_GUID 101c7129-35cb-5f03-9578-aa21b3141db7) 25 | set(FBControl_GUID 5c3f77ce-6f14-56f3-ab90-81db091b5ab3) 26 | set(IFBComJavascriptObject_GUID 7d985eef-36cb-5eda-bebb-652a434a6a1b) 27 | set(FBComJavascriptObject_GUID 970c4c99-e68e-5041-b0d4-66bf53425382) 28 | set(IFBComEventSource_GUID 48ce3cd8-8b34-565a-9aef-0dada3bee81c) 29 | if ( FB_PLATFORM_ARCH_32 ) 30 | set(FBControl_WixUpgradeCode_GUID 779c6b78-b4f8-5a73-929a-f8c14b31bb2d) 31 | else ( FB_PLATFORM_ARCH_32 ) 32 | set(FBControl_WixUpgradeCode_GUID 2f0941f6-e103-5ac7-adee-807aa105f215) 33 | endif ( FB_PLATFORM_ARCH_32 ) 34 | 35 | # these are the pieces that are relevant to using it from Javascript 36 | set(ACTIVEX_PROGID "InventiveDesigners.WebCryptoKeyandCertificateDiscovery") 37 | set(MOZILLA_PLUGINID "inventivedesigners.com/WebCryptoKeyandCertificateDiscovery") 38 | 39 | # strings 40 | set(FBSTRING_CompanyName "Inventive Designers") 41 | set(FBSTRING_PluginDescription "This plug-in will add support for the Web Crypto Key and Certificate Discovery API to your browser.") 42 | set(FBSTRING_PLUGIN_VERSION "1.0.0.0") 43 | set(FBSTRING_LegalCopyright "Copyright 2013 Inventive Designers") 44 | set(FBSTRING_PluginFileName "np${PLUGIN_NAME}.dll") 45 | set(FBSTRING_ProductName "Web Crypto Key and Certificate Discovery") 46 | set(FBSTRING_FileExtents "") 47 | if ( FB_PLATFORM_ARCH_32 ) 48 | set(FBSTRING_PluginName "Web Crypto Key and Certificate Discovery") # No 32bit postfix to maintain backward compatability. 49 | else ( FB_PLATFORM_ARCH_32 ) 50 | set(FBSTRING_PluginName "Web Crypto Key and Certificate Discovery_${FB_PLATFORM_ARCH_NAME}") 51 | endif ( FB_PLATFORM_ARCH_32 ) 52 | set(FBSTRING_MIMEType "application/x-webcryptokeyandcertificatediscovery") 53 | 54 | # Uncomment this next line if you're not planning on your plugin doing 55 | # any drawing: 56 | 57 | #set (FB_GUI_DISABLED 1) 58 | 59 | # Mac plugin settings. If your plugin does not draw, set these all to 0 60 | set(FBMAC_USE_QUICKDRAW 0) 61 | set(FBMAC_USE_CARBON 1) 62 | set(FBMAC_USE_COCOA 1) 63 | set(FBMAC_USE_COREGRAPHICS 1) 64 | set(FBMAC_USE_COREANIMATION 0) 65 | set(FBMAC_USE_INVALIDATINGCOREANIMATION 0) 66 | 67 | # If you want to register per-machine on Windows, uncomment this line 68 | #set (FB_ATLREG_MACHINEWIDE 1) 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | webcrypto-key-certificate-discovery-js 2 | ====================================== 3 | 4 | A native plugin for modern browsers that implements a [X509 Certificate Selector API](https://github.com/InventiveDesigners/webcrypto-key-certificate-discovery-js/wiki/API) 5 | which is closely integrated with the [Web crypto API](http://www.w3.org/TR/WebCryptoAPI). 6 | 7 | See [wiki](https://github.com/InventiveDesigners/webcrypto-key-certificate-discovery-js/wiki) at github for more information. 8 | -------------------------------------------------------------------------------- /Test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | test page for Web Crypto 4 | 5 | 6 | 7 | 8 | 190 | 191 | 209 | 210 | 211 | 212 |
213 | 214 | Load Certificates 215 | Sign 216 | 217 |
    218 |
219 |
220 | 221 | 222 | -------------------------------------------------------------------------------- /WebCryptoKeyandCertificateDiscovery.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated WebCryptoKeyandCertificateDiscovery.cpp 18 | 19 | This file contains the auto-generated main plugin object 20 | implementation for the Web Crypto Key and Certificate Discovery project 21 | 22 | \**********************************************************/ 23 | 24 | #include "WebCryptoKeyandCertificateDiscoveryAPI.h" 25 | 26 | #include "WebCryptoKeyandCertificateDiscovery.h" 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | /// @fn WebCryptoKeyandCertificateDiscovery::StaticInitialize() 30 | /// 31 | /// @brief Called from PluginFactory::globalPluginInitialize() 32 | /// 33 | /// @see FB::FactoryBase::globalPluginInitialize 34 | /////////////////////////////////////////////////////////////////////////////// 35 | void WebCryptoKeyandCertificateDiscovery::StaticInitialize() 36 | { 37 | // Place one-time initialization stuff here; As of FireBreath 1.4 this should only 38 | // be called once per process 39 | } 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | /// @fn WebCryptoKeyandCertificateDiscovery::StaticInitialize() 43 | /// 44 | /// @brief Called from PluginFactory::globalPluginDeinitialize() 45 | /// 46 | /// @see FB::FactoryBase::globalPluginDeinitialize 47 | /////////////////////////////////////////////////////////////////////////////// 48 | void WebCryptoKeyandCertificateDiscovery::StaticDeinitialize() 49 | { 50 | // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should 51 | // always be called just before the plugin library is unloaded 52 | } 53 | 54 | /////////////////////////////////////////////////////////////////////////////// 55 | /// @brief WebCryptoKeyandCertificateDiscovery constructor. Note that your API is not available 56 | /// at this point, nor the window. For best results wait to use 57 | /// the JSAPI object until the onPluginReady method is called 58 | /////////////////////////////////////////////////////////////////////////////// 59 | WebCryptoKeyandCertificateDiscovery::WebCryptoKeyandCertificateDiscovery() 60 | { 61 | } 62 | 63 | /////////////////////////////////////////////////////////////////////////////// 64 | /// @brief WebCryptoKeyandCertificateDiscovery destructor. 65 | /////////////////////////////////////////////////////////////////////////////// 66 | WebCryptoKeyandCertificateDiscovery::~WebCryptoKeyandCertificateDiscovery() 67 | { 68 | // This is optional, but if you reset m_api (the shared_ptr to your JSAPI 69 | // root object) and tell the host to free the retained JSAPI objects then 70 | // unless you are holding another shared_ptr reference to your JSAPI object 71 | // they will be released here. 72 | releaseRootJSAPI(); 73 | m_host->freeRetainedObjects(); 74 | } 75 | 76 | void WebCryptoKeyandCertificateDiscovery::onPluginReady() 77 | { 78 | // When this is called, the BrowserHost is attached, the JSAPI object is 79 | // created, and we are ready to interact with the page and such. The 80 | // PluginWindow may or may not have already fire the AttachedEvent at 81 | // this point. 82 | } 83 | 84 | void WebCryptoKeyandCertificateDiscovery::shutdown() 85 | { 86 | // This will be called when it is time for the plugin to shut down; 87 | // any threads or anything else that may hold a shared_ptr to this 88 | // object should be released here so that this object can be safely 89 | // destroyed. This is the last point that shared_from_this and weak_ptr 90 | // references to this object will be valid 91 | } 92 | 93 | /////////////////////////////////////////////////////////////////////////////// 94 | /// @brief Creates an instance of the JSAPI object that provides your main 95 | /// Javascript interface. 96 | /// 97 | /// Note that m_host is your BrowserHost and shared_ptr returns a 98 | /// FB::PluginCorePtr, which can be used to provide a 99 | /// boost::weak_ptr for your JSAPI class. 100 | /// 101 | /// Be very careful where you hold a shared_ptr to your plugin class from, 102 | /// as it could prevent your plugin class from getting destroyed properly. 103 | /////////////////////////////////////////////////////////////////////////////// 104 | FB::JSAPIPtr WebCryptoKeyandCertificateDiscovery::createJSAPI() 105 | { 106 | // m_host is the BrowserHost 107 | return boost::make_shared(FB::ptr_cast(shared_from_this()), m_host); 108 | } 109 | 110 | bool WebCryptoKeyandCertificateDiscovery::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *) 111 | { 112 | // The window is attached; act appropriately 113 | return false; 114 | } 115 | 116 | bool WebCryptoKeyandCertificateDiscovery::onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *) 117 | { 118 | // The window is about to be detached; act appropriately 119 | return false; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /WebCryptoKeyandCertificateDiscovery.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated WebCryptoKeyandCertificateDiscovery.h 18 | 19 | This file contains the auto-generated main plugin object 20 | implementation for the Web Crypto Key and Certificate Discovery project 21 | 22 | \**********************************************************/ 23 | #ifndef H_WebCryptoKeyandCertificateDiscoveryPLUGIN 24 | #define H_WebCryptoKeyandCertificateDiscoveryPLUGIN 25 | 26 | #include "PluginWindow.h" 27 | #include "PluginEvents/MouseEvents.h" 28 | #include "PluginEvents/AttachedEvent.h" 29 | 30 | #include "PluginCore.h" 31 | 32 | 33 | FB_FORWARD_PTR(WebCryptoKeyandCertificateDiscovery) 34 | class WebCryptoKeyandCertificateDiscovery : public FB::PluginCore 35 | { 36 | public: 37 | static void StaticInitialize(); 38 | static void StaticDeinitialize(); 39 | 40 | public: 41 | WebCryptoKeyandCertificateDiscovery(); 42 | virtual ~WebCryptoKeyandCertificateDiscovery(); 43 | 44 | public: 45 | void onPluginReady(); 46 | void shutdown(); 47 | virtual FB::JSAPIPtr createJSAPI(); 48 | // If you want your plugin to always be windowless, set this to true 49 | // If you want your plugin to be optionally windowless based on the 50 | // value of the "windowless" param tag, remove this method or return 51 | // FB::PluginCore::isWindowless() 52 | virtual bool isWindowless() { return false; } 53 | 54 | BEGIN_PLUGIN_EVENT_MAP() 55 | EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindow) 56 | EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindow) 57 | END_PLUGIN_EVENT_MAP() 58 | 59 | /** BEGIN EVENTDEF -- DON'T CHANGE THIS LINE **/ 60 | virtual bool onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *); 61 | virtual bool onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *); 62 | /** END EVENTDEF -- DON'T CHANGE THIS LINE **/ 63 | }; 64 | 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /WebCryptoKeyandCertificateDiscoveryAPI.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated WebCryptoKeyandCertificateDiscoveryAPI.cpp 18 | 19 | \**********************************************************/ 20 | 21 | #include "JSObject.h" 22 | #include "variant_list.h" 23 | #include "DOM/Document.h" 24 | #include "global/config.h" 25 | 26 | #include "WebCryptoKeyandCertificateDiscoveryAPI.h" 27 | 28 | #include "X509CertificateSelector.h" 29 | 30 | FB::JSAPIPtr WebCryptoKeyandCertificateDiscoveryAPI::createX509CertificateSelector(FB::VariantMap selectorParams) 31 | { 32 | return boost::shared_ptr(new X509CertificateSelector(m_host)); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /WebCryptoKeyandCertificateDiscoveryAPI.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated WebCryptoKeyandCertificateDiscoveryAPI.h 18 | 19 | \**********************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "JSAPIAuto.h" 25 | #include "BrowserHost.h" 26 | #include "WebCryptoKeyandCertificateDiscovery.h" 27 | #include "Algorithm.h" 28 | #include "Key.h" 29 | #include "CryptoOperation.h" 30 | 31 | #ifndef H_WebCryptoKeyandCertificateDiscoveryAPI 32 | #define H_WebCryptoKeyandCertificateDiscoveryAPI 33 | 34 | class WebCryptoKeyandCertificateDiscoveryAPI : public FB::JSAPIAuto 35 | { 36 | public: 37 | //////////////////////////////////////////////////////////////////////////// 38 | /// @fn WebCryptoKeyandCertificateDiscoveryAPI::WebCryptoKeyandCertificateDiscoveryAPI(const WebCryptoKeyandCertificateDiscoveryPtr& plugin, const FB::BrowserHostPtr host) 39 | /// 40 | /// @brief Constructor for your JSAPI object. 41 | /// You should register your methods, properties, and events 42 | /// that should be accessible to Javascript from here. 43 | /// 44 | /// @see FB::JSAPIAuto::registerMethod 45 | /// @see FB::JSAPIAuto::registerProperty 46 | /// @see FB::JSAPIAuto::registerEvent 47 | //////////////////////////////////////////////////////////////////////////// 48 | WebCryptoKeyandCertificateDiscoveryAPI(const WebCryptoKeyandCertificateDiscoveryPtr& plugin, const FB::BrowserHostPtr& host) : 49 | m_plugin(plugin), m_host(host) 50 | { 51 | registerMethod("createX509CertificateSelector", make_method(this, &WebCryptoKeyandCertificateDiscoveryAPI::createX509CertificateSelector)); 52 | registerMethod("encrypt", make_method(this, &WebCryptoKeyandCertificateDiscoveryAPI::encrypt)); 53 | 54 | } 55 | 56 | /////////////////////////////////////////////////////////////////////////////// 57 | /// @fn WebCryptoKeyandCertificateDiscoveryAPI::~WebCryptoKeyandCertificateDiscoveryAPI() 58 | /// 59 | /// @brief Destructor. Remember that this object will not be released until 60 | /// the browser is done with it; this will almost definitely be after 61 | /// the plugin is released. 62 | /////////////////////////////////////////////////////////////////////////////// 63 | virtual ~WebCryptoKeyandCertificateDiscoveryAPI() {}; 64 | 65 | WebCryptoKeyandCertificateDiscoveryPtr getPlugin(); 66 | 67 | FB::JSAPIPtr createX509CertificateSelector(FB::VariantMap selectorParams); 68 | boost::shared_ptr encrypt(boost::shared_ptr algorithm, boost::shared_ptr key, boost::optional base64Buffer); 69 | 70 | private: 71 | WebCryptoKeyandCertificateDiscoveryWeakPtr m_plugin; 72 | FB::BrowserHostPtr m_host; 73 | 74 | std::string m_testString; 75 | }; 76 | 77 | #endif // H_WebCryptoKeyandCertificateDiscoveryAPI 78 | 79 | -------------------------------------------------------------------------------- /Win/WebCryptoKeyandCertificateDiscoveryAPI.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /**********************************************************\ 16 | 17 | Auto-generated WebCryptoKeyandCertificateDiscoveryAPI.cpp 18 | 19 | \**********************************************************/ 20 | 21 | #include "JSObject.h" 22 | #include "variant_list.h" 23 | #include "DOM/Document.h" 24 | #include "global/config.h" 25 | 26 | #include "../WebCryptoKeyandCertificateDiscoveryAPI.h" 27 | 28 | 29 | boost::shared_ptr WebCryptoKeyandCertificateDiscoveryAPI::encrypt(boost::shared_ptr algorithm, boost::shared_ptr key, boost::optional base64Buffer) 30 | { 31 | boost::shared_ptr result; 32 | return result; 33 | } -------------------------------------------------------------------------------- /Win/WiX/WebCryptoKeyandCertificateDiscovery.ddf: -------------------------------------------------------------------------------- 1 | ; 2 | .Set DiskDirectoryTemplate=%OUTDIR%/ 3 | .Set CabinetNameTemplate=${PROJECT_NAME}.cab 4 | .Set Cabinet=on 5 | .Set Compress=on 6 | .Set MaxDiskSize=0 7 | %OUTDIR%/${PROJECT_NAME}.exe 8 | ${CMAKE_CURRENT_BINARY_DIR}/WebCryptoKeyandCertificateDiscovery.inf 9 | ; -------------------------------------------------------------------------------- /Win/WiX/WebCryptoKeyandCertificateDiscovery.inf: -------------------------------------------------------------------------------- 1 | [version] 2 | Signature="$CHICAGO$" 3 | AdvancedINF=2.0 4 | 5 | [Setup Hooks] 6 | hook1=hook1 7 | 8 | [hook1] 9 | run="%EXTRACT_DIR%\${PROJECT_NAME}.exe" -------------------------------------------------------------------------------- /Win/WiX/WebCryptoKeyandCertificateDiscoveryInstaller.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | 35 | 36 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Win/X509CertificateImpl.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateImpl.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #include "X509CertificateImpl.h" 24 | #include "../Key.h" 25 | 26 | X509CertificateImpl::X509CertificateImpl(const FB::BrowserHostPtr& host, std::string name) : X509Certificate(host, name) 27 | { 28 | } 29 | 30 | FB::JSAPIPtr X509CertificateImpl::get_issuerX500Principal() 31 | { 32 | // TODO implement 33 | return boost::shared_ptr(new X500Principal(m_host, L"")); 34 | } 35 | 36 | FB::FBDateString X509CertificateImpl::get_notAfter() 37 | { 38 | // TODO implement 39 | return FB::FBDateString(); 40 | } 41 | 42 | FB::FBDateString X509CertificateImpl::get_notBefore() 43 | { 44 | // TODO implement 45 | return FB::FBDateString(); 46 | } 47 | 48 | FB::JSAPIPtr X509CertificateImpl::get_privateKey() 49 | { 50 | // TODO fill in parameters 51 | return boost::shared_ptr(new Key(m_host, "private", false, Algorithm(m_host, "Boe", FB::VariantMap()), FB::VariantList())); 52 | } 53 | 54 | std::string X509CertificateImpl::get_serialNumber() 55 | { 56 | // TODO implement 57 | return "0"; 58 | } 59 | 60 | 61 | FB::JSAPIPtr X509CertificateImpl::get_subjectX500Principal() 62 | { 63 | // TODO implement 64 | return boost::shared_ptr(new X500Principal(m_host, L"")); 65 | } 66 | 67 | 68 | long X509CertificateImpl::get_version() 69 | { 70 | // TODO implement 71 | return 3; 72 | } 73 | 74 | 75 | FB::VariantList X509CertificateImpl::get_keyUsage() 76 | { 77 | // TODO implement 78 | return FB::VariantList(); 79 | } 80 | -------------------------------------------------------------------------------- /Win/X509CertificateImpl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateImpl.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__X509CertificateImpl__ 24 | #define __FireBreath__X509CertificateImpl__ 25 | 26 | #include "../X509Certificate.h" 27 | 28 | class X509CertificateImpl: public X509Certificate 29 | { 30 | public: 31 | X509CertificateImpl(const FB::BrowserHostPtr& host, std::string name); 32 | virtual ~X509CertificateImpl() {}; 33 | 34 | X509CertificateImpl(const X509CertificateImpl& other); 35 | X509CertificateImpl& operator=(const X509CertificateImpl& other); 36 | 37 | virtual FB::JSAPIPtr get_issuerX500Principal(); 38 | virtual FB::FBDateString get_notAfter(); 39 | virtual FB::FBDateString get_notBefore(); 40 | virtual FB::JSAPIPtr get_privateKey(void); 41 | virtual std::string get_serialNumber(); 42 | virtual FB::JSAPIPtr get_subjectX500Principal(); 43 | virtual long get_version(); 44 | virtual FB::VariantList get_keyUsage(); // See rfc5280 for more information 45 | }; 46 | 47 | #endif /* defined(__FireBreath__X509CertificateImpl__) */ 48 | -------------------------------------------------------------------------------- /Win/X509CertificateImpl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateImpl.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__X509CertificateImpl__ 24 | #define __FireBreath__X509CertificateImpl__ 25 | 26 | #include "../X509Certificate.h" 27 | 28 | class X509CertificateImpl: public X509Certificate 29 | { 30 | public: 31 | X509CertificateImpl(const FB::BrowserHostPtr& host, std::string name); 32 | virtual ~X509CertificateImpl() {}; 33 | 34 | X509CertificateImpl(const X509CertificateImpl& other); 35 | X509CertificateImpl& operator=(const X509CertificateImpl& other); 36 | 37 | virtual FB::JSAPIPtr get_issuerX500Principal(); 38 | virtual FB::FBDateString get_notAfter(); 39 | virtual FB::FBDateString get_notBefore(); 40 | virtual FB::JSAPIPtr get_privateKey(); 41 | virtual std::string get_serialNumber(); 42 | virtual FB::JSAPIPtr get_subjectX500Principal(); 43 | virtual long get_version(); 44 | virtual FB::VariantList get_keyUsage(); // See rfc5280 for more information 45 | }; 46 | 47 | #endif /* defined(__FireBreath__X509CertificateImpl__) */ 48 | -------------------------------------------------------------------------------- /Win/X509CertificateSelectorWorkerFunc.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../X509CertificateSelector.h" 23 | #include "X509CertificateImpl.h" 24 | 25 | void X509CertificateSelectorWorkerFunc(X509CertificateSelector * selector) 26 | { 27 | HCERTSTORE hCertStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, L"MY"); 28 | 29 | if(!hCertStore) 30 | { 31 | selector->FireJSEvent("onerror", FB::VariantMap(), FB::variant_list_of()); 32 | } 33 | 34 | PCCERT_CONTEXT pCertContext=NULL; 35 | wchar_t pszNameString[128]; 36 | FB::VariantList result; 37 | while(pCertContext= CertEnumCertificatesInStore(hCertStore, pCertContext)) 38 | { 39 | CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, pszNameString, 128); 40 | std::wstring description = std::wstring((wchar_t*)&pszNameString); 41 | result.push_back(FB::make_variant(boost::shared_ptr(new X509CertificateImpl(selector->m_host, std::string(description.begin(), description.end()))))); 42 | } 43 | 44 | selector->set_result(result); 45 | selector->FireJSEvent("oncomplete", FB::VariantMap(), FB::variant_list_of()); 46 | } 47 | -------------------------------------------------------------------------------- /Win/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated Windows project definition file for the 3 | # Web Crypto Key and Certificate Discovery project 4 | #\**********************************************************/ 5 | 6 | # Windows template platform definition CMake file 7 | # Included from ../CMakeLists.txt 8 | 9 | # remember that the current source dir is the project root; this file is in Win/ 10 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | Win/[^.]*.cpp 12 | Win/[^.]*.h 13 | Win/[^.]*.cmake 14 | ) 15 | 16 | # use this to add preprocessor definitions 17 | add_definitions( 18 | /D "_ATL_STATIC_REGISTRY" 19 | ) 20 | 21 | SOURCE_GROUP(Win FILES ${PLATFORM}) 22 | 23 | set (SOURCES 24 | ${SOURCES} 25 | ${PLATFORM} 26 | ) 27 | 28 | add_windows_plugin(${PROJECT_NAME} SOURCES) 29 | 30 | # This is an example of how to add a build step to sign the plugin DLL before 31 | # the WiX installer builds. The first filename (certificate.pfx) should be 32 | # the path to your pfx file. If it requires a passphrase, the passphrase 33 | # should be located inside the second file. If you don't need a passphrase 34 | # then set the second filename to "". If you don't want signtool to timestamp 35 | # your DLL then make the last parameter "". 36 | # 37 | # Note that this will not attempt to sign if the certificate isn't there -- 38 | # that's so that you can have development machines without the cert and it'll 39 | # still work. Your cert should only be on the build machine and shouldn't be in 40 | # source control! 41 | # -- uncomment lines below this to enable signing -- 42 | #firebreath_sign_plugin(${PROJECT_NAME} 43 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 44 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 45 | # "http://timestamp.verisign.com/scripts/timestamp.dll") 46 | 47 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 48 | target_link_libraries(${PROJECT_NAME} 49 | ${PLUGIN_INTERNAL_DEPS} 50 | Crypt32.lib 51 | ) 52 | 53 | set(WIX_HEAT_FLAGS 54 | -gg # Generate GUIDs 55 | -srd # Suppress Root Dir 56 | -cg PluginDLLGroup # Set the Component group name 57 | -dr INSTALLDIR # Set the directory ID to put the files in 58 | ) 59 | 60 | add_wix_installer( ${PLUGIN_NAME} 61 | ${CMAKE_CURRENT_SOURCE_DIR}/Win/WiX/WebCryptoKeyandCertificateDiscoveryInstaller.wxs 62 | PluginDLLGroup 63 | ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/ 64 | ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${FBSTRING_PluginFileName}.dll 65 | ${PROJECT_NAME} 66 | ) 67 | 68 | # This is an example of how to add a build step to sign the WiX installer 69 | # -- uncomment lines below this to enable signing -- 70 | #firebreath_sign_file("${PLUGIN_NAME}_WiXInstall" 71 | # "${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}.msi" 72 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 73 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 74 | # "http://timestamp.verisign.com/scripts/timestamp.dll") 75 | 76 | # This is an example of how to create a cab 77 | # -- uncomment lines below this to enable signing -- 78 | #create_cab(${PLUGIN_NAME} 79 | # ${CMAKE_CURRENT_SOURCE_DIR}/Win/Wix/WebCryptoKeyandCertificateDiscovery.ddf 80 | # ${CMAKE_CURRENT_SOURCE_DIR}/Win/Wix/WebCryptoKeyandCertificateDiscovery.inf 81 | # ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/ 82 | # ${PROJECT_NAME}_WiXInstallExe 83 | # ) 84 | -------------------------------------------------------------------------------- /X11/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated X11 project definition file for the 3 | # Web Crypto Key and Certificate Discovery project 4 | #\**********************************************************/ 5 | 6 | # X11 template platform definition CMake file 7 | # Included from ../CMakeLists.txt 8 | 9 | # remember that the current source dir is the project root; this file is in X11/ 10 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | X11/[^.]*.cpp 12 | X11/[^.]*.h 13 | X11/[^.]*.cmake 14 | ) 15 | 16 | SOURCE_GROUP(X11 FILES ${PLATFORM}) 17 | 18 | # use this to add preprocessor definitions 19 | add_definitions( 20 | ) 21 | 22 | set (SOURCES 23 | ${SOURCES} 24 | ${PLATFORM} 25 | ) 26 | 27 | add_x11_plugin(${PROJECT_NAME} SOURCES) 28 | 29 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 30 | target_link_libraries(${PROJECT_NAME} 31 | ${PLUGIN_INTERNAL_DEPS} 32 | ) 33 | -------------------------------------------------------------------------------- /X500Principal.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X500Principal.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #include "X500Principal.h" 24 | 25 | X500Principal::X500Principal(const FB::BrowserHostPtr& host, std::wstring name) : JSAPIAuto(std::string(name.begin(), name.end())), m_host(host), m_name(name) 26 | { 27 | initializeProperties(); 28 | } 29 | 30 | X500Principal::X500Principal(const X500Principal&other) : JSAPIAuto(std::string(other.m_name.begin(), other.m_name.end())), m_host(other.m_host), m_name(other.m_name) 31 | { 32 | initializeProperties(); 33 | } 34 | 35 | X500Principal& X500Principal::operator=(const X500Principal& other) 36 | { 37 | m_host = other.m_host; 38 | m_name = other.m_name; 39 | 40 | initializeProperties(); 41 | 42 | return *this; 43 | } 44 | 45 | std::wstring X500Principal::get_name() 46 | { 47 | return m_name; 48 | } 49 | 50 | void X500Principal::initializeProperties() 51 | { 52 | registerProperty("name", make_property(this, &X500Principal::get_name)); 53 | } -------------------------------------------------------------------------------- /X500Principal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X500Principal.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 25/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__X500Principal__ 24 | #define __FireBreath__X500Principal__ 25 | 26 | #include "JSAPIAuto.h" 27 | #include "BrowserHost.h" 28 | 29 | class X500Principal : public FB::JSAPIAuto 30 | { 31 | public: 32 | X500Principal(const FB::BrowserHostPtr& host, std::wstring name); 33 | virtual ~X500Principal() {}; 34 | 35 | X500Principal(const X500Principal& other); 36 | X500Principal& operator=(const X500Principal& other); 37 | 38 | std::wstring get_name(); 39 | 40 | protected: 41 | FB::BrowserHostPtr m_host; 42 | std::wstring m_name; 43 | 44 | private: 45 | void initializeProperties(); 46 | }; 47 | 48 | #endif /* defined(__FireBreath__X500Principal__) */ 49 | -------------------------------------------------------------------------------- /X509Certificate.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509Certificate.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 22/03/13. 20 | // 21 | // 22 | 23 | #include "X509Certificate.h" 24 | 25 | X509Certificate::X509Certificate(const FB::BrowserHostPtr& host, std::string name) : JSAPIAuto(name), m_host(host) 26 | { 27 | initializeProperties(); 28 | } 29 | 30 | void X509Certificate::initializeProperties() 31 | { 32 | registerProperty("issuerX500Principal", make_property(this, &X509Certificate::get_issuerX500Principal)); 33 | 34 | // TODO register notAfter and notBefore (type is commented out) 35 | //registerProperty("notAfter", make_property(this, &X509Certificate::get_notAfter)); 36 | //registerProperty("notBefore", make_property(this, &X509Certificate::get_notBefore)); 37 | // registerProperty("publicKey", make_property(this, &X509Certificate::get_publicKey)); 38 | registerProperty("privateKey", make_property(this, &X509Certificate::get_privateKey)); 39 | registerProperty("serialNumber", make_property(this, &X509Certificate::get_serialNumber)); 40 | registerProperty("subjectX500Principal", make_property(this, &X509Certificate::get_subjectX500Principal)); 41 | registerProperty("version", make_property(this, &X509Certificate::get_version)); 42 | registerProperty("keyUsage", make_property(this, &X509Certificate::get_keyUsage)); // See rfc5280 for more information 43 | // registerProperty("extendedKeyUsage", make_property(this, &X509Certificate::get_extendedKeyUsage)); // See rfc5280 for more information 44 | } 45 | 46 | -------------------------------------------------------------------------------- /X509Certificate.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509Certificate.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 22/03/13. 20 | // 21 | // 22 | 23 | #ifndef H_X509Certificate 24 | #define H_X509Certificate 25 | 26 | #include 27 | 28 | #include "JSAPIAuto.h" 29 | #include "BrowserHost.h" 30 | #include "X500Principal.h" 31 | 32 | 33 | class X509Certificate : public FB::JSAPIAuto 34 | { 35 | public: 36 | X509Certificate(const FB::BrowserHostPtr& host, std::string name); 37 | virtual ~X509Certificate() {}; 38 | 39 | virtual FB::JSAPIPtr get_issuerX500Principal() = 0; 40 | virtual FB::FBDateString get_notAfter() = 0; 41 | virtual FB::FBDateString get_notBefore() = 0; 42 | //get_publicKey 43 | virtual FB::JSAPIPtr get_privateKey() = 0; 44 | virtual std::string get_serialNumber() = 0; 45 | virtual FB::JSAPIPtr get_subjectX500Principal() = 0; 46 | virtual long get_version() = 0; 47 | virtual FB::VariantList get_keyUsage() = 0; // See rfc5280 for more information 48 | // get_extendedKeyUsage; // See rfc5280 for more information 49 | 50 | 51 | protected: 52 | FB::BrowserHostPtr m_host; 53 | 54 | private: 55 | void initializeProperties(); 56 | }; 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /X509CertificateSelector.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateSelector.cpp 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 22/03/13. 20 | // 21 | // 22 | 23 | #include "X509CertificateSelector.h" 24 | 25 | #include 26 | #include 27 | 28 | void X509CertificateSelectorWorkerFunc(X509CertificateSelector * selector); 29 | 30 | X509CertificateSelector::X509CertificateSelector(const FB::BrowserHostPtr& host) : KeyOperation(host) 31 | { 32 | initializeMethods(); 33 | } 34 | 35 | void X509CertificateSelector::initializeMethods() 36 | { 37 | registerMethod("execute", make_method(this, &X509CertificateSelector::execute)); 38 | } 39 | 40 | 41 | void X509CertificateSelector::execute() 42 | { 43 | boost::thread workerThread(X509CertificateSelectorWorkerFunc, this); 44 | } 45 | -------------------------------------------------------------------------------- /X509CertificateSelector.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Inventive Designers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 16 | // X509CertificateSelector.h 17 | // FireBreath 18 | // 19 | // Created by Nick Van den Bleeken on 22/03/13. 20 | // 21 | // 22 | 23 | #ifndef __FireBreath__X509CertificateSelector__ 24 | #define __FireBreath__X509CertificateSelector__ 25 | 26 | #include "JSAPIAuto.h" 27 | #include "BrowserHost.h" 28 | #include "KeyOperation.h" 29 | 30 | class X509CertificateSelector : public KeyOperation 31 | { 32 | friend void X509CertificateSelectorWorkerFunc(X509CertificateSelector * selector); 33 | public: 34 | X509CertificateSelector(const FB::BrowserHostPtr& host); 35 | virtual ~X509CertificateSelector() {}; 36 | 37 | void execute(); 38 | 39 | private: 40 | void initializeMethods(); 41 | }; 42 | 43 | #endif /* defined(__FireBreath__X509CertificateSelector__) */ 44 | -------------------------------------------------------------------------------- /prep2012.cmd: -------------------------------------------------------------------------------- 1 | call .\firebreath\prep2012.cmd . build "-DBOOST_ROOT=C:\Program Files\boost" "-DWITH_SYSTEM_BOOST=1" "-DBoost_USE_STATIC_LIBS=on" "-DBoost_USE_STATIC_RUNTIME=on" 2 | -------------------------------------------------------------------------------- /prep2012x64.cmd: -------------------------------------------------------------------------------- 1 | call .\firebreath\prep2012x64.cmd . build "-DBOOST_ROOT=C:\Program Files\boost" "-DWITH_SYSTEM_BOOST=1" "-DBoost_USE_STATIC_LIBS=on" "-DBoost_USE_STATIC_RUNTIME=on" 2 | -------------------------------------------------------------------------------- /prepmac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ./firebreath/prepmac.sh . build -D BOOST_ROOT=/usr/local/include/boost -DWITH_SYSTEM_BOOST=1 -D Boost_USE_STATIC_LIBS=on -D Boost_USE_STATIC_RUNTIME=on 3 | -------------------------------------------------------------------------------- /xpi/content/chrome.manifest: -------------------------------------------------------------------------------- 1 | binary-component plugins/npWebCryptoKeyandCertificateDiscovery abi=WINNT_x86-MSVC -------------------------------------------------------------------------------- /xpi/content/install.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | EMAIL_ADDRESS_HERE 6 | WebCryptoKeyandCertificateDiscovery 7 | ${FBSTRING_PLUGIN_VERSION} 8 | 9 | 11 | true 12 | 13 | 14 | 15 | en-US 16 | Web Crypto Key and Certificate Discovery 17 | This plug-in will add support for the Web Crypto Key and Certificate Discovery API to your browser. 18 | Inventive Designers 19 | http://inventivedesigners.com 20 | 21 | 22 | 23 | 24 | 25 | 26 | {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 27 | 3.* 28 | 10.* 29 | 30 | 31 | 32 | 33 | WINNT_x86-msvc 34 | 35 | 36 | --------------------------------------------------------------------------------