Setup all relevant properties of the given certificate to produce
 a valid and useable certificate.
778455
def configure(cert)
      req = signing_request
      cert.issuer = Billy.certificate_authority.cert.subject
      cert.not_before = days_ago(2)
      cert.not_after = days_from_now(2)
      cert.public_key = req.public_key
      cert.serial = serial
      cert.subject = req.subject
      cert.version = 2
    end
875577
def _init_ssl(self):
        

        if not have_openssl:
            raise ImportError('SSL sockets have been disabled due to missing requirement: pyopenssl.')

        try:
            ctx = SSL.Context(SSL.TLSv1_METHOD)

            if isinstance(self.ssl_key, crypto.PKey):
                ctx.use_privatekey(self.ssl_key)
            else:
                ctx.use_privatekey_file(self.ssl_key)

            if isinstance(self.ssl_certificate, crypto.X509):
                ctx.use_certificate(self.ssl_certificate)
            else:
                ctx.use_certificate_file(self.ssl_certificate)

            if isinstance(self.ssl_ca, crypto.X509):
                store = ctx.get_cert_store()
                store.add_cert(self.ssl_ca)
            else:
                ctx.load_verify_locations(self.ssl_ca, None)

            verify_method = SSL.VERIFY_PEER
            if (self._ssl_allow_self_signed):
                verify_method = SSL.VERIFY_NONE

            ctx.set_verify(verify_method, self._verify_ssl_callback)

            self._device = SSL.Connection(ctx, self._device)

        except SSL.Error as err:
            raise CommError('Error setting up SSL connection.', err)
54161
def validate(self):
        """"""

        if not self.server.enabled:

            if self.security.signature_certificate_file is self.security.defaults['signature_certificate_file']:
                print("ISSUE: If you are not configuring a server, you need to set 'signature_certificate_file'")

            if self.security.signature_private_key_file is self.security.defaults['signature_private_key_file']:
                print("ISSUE: If you are not configuring a server, you need to set 'signature_private_key_file'")

        else:

            if self.client.enabled:
                print("ISSUE: Client and server enabled at the same time?")

            if self.server.protocol is self.server.defaults['protocol']:
                if self.server.server_certificate_file is self.server.defaults['server_certificate_file'] or \
                                self.server.server_private_key_file is self.server.defaults['server_private_key_file']:
                   print("ISSUE: 'server_certificate_file' and/or 'server_private_key_file' are not configured and will be auto-generated.")


            if self.server.certification_authority_certificate_file is self.server.defaults['certification_authority_certificate_file'] or \
                            self.server.certification_authority_private_key_file is self.server.defaults['certification_authority_private_key_file']:
                print("ISSUE: 'certification_authority_certificate_file' and/or 'certification_authority_private_key_file' are not configured and will be auto-generated - this is NOT recommended.")

            if self.server.authentication_script is self.server.defaults['authentication_script']:
                print("ISSUE: No 'authentication_script' has been provided and all authentication requests will be rejected!")

        if self.client.enabled:

            if self.client.server_endpoint is self.client.defaults['server_endpoint']:
                print("ISSUE: You are running in client mode, but you are using a default server address.")

            if not self.client.disable_peer_verification is self.client.defaults['disable_peer_verification'] or \
                    not self.client.disable_host_verification is self.client.defaults['disable_host_verification']:
                print("ISSUE: Disabling peer/host verification is NOT recommended - AT ALL.")

            if self.client.username is self.client.defaults['username'] or \
                            self.client.password is self.client.defaults['password']:
                print("ISSUE: No username and/or password has been configured for a client.")

        if self.fscp.contact is self.fscp.defaults['contact']:

            if not self.server.enabled and not self.client.enabled:
                print("ISSUE: You have not defined any contact points while you are neither running as server nor client.")

        ## hostname_resolution_protocol=ipv4/ipv6
        ## ipv4_address_prefix_length=9.0.0.1/24
        ## ipv6_address_prefix_length=2aa1::1/8

        if self.security.authority_certificate_file is self.security.defaults['authority_certificate_file']:
            print("ISSUE: You need to set 'authority_certificate_file'")

        if self.tap_adapter.ipv4_address_prefix_length is self.tap_adapter.defaults['ipv4_address_prefix_length']:
            print("ISSUE: You are using the default network address - make sure you set a different ip for every machine 'ipv4_address_prefix_length'")
524014
private function configure()
    {
        $keyCert = SignatureUtils::generateKeyCert($this->settings);
        $dir = dirname($this->settings['sp_key_file']);
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException('The directory you selected for sp_key_file does not exist. Please create ' . $dir);
        }
        $dir = dirname($this->settings['sp_cert_file']);
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException('The directory you selected for sp_cert_file does not exist. Please create ' . $dir);
        }
        file_put_contents($this->settings['sp_key_file'], $keyCert['key']);
        file_put_contents($this->settings['sp_cert_file'], $keyCert['cert']);
    }
121218
def _prepare_conn(self, conn):
        

        if isinstance(conn, VerifiedHTTPSConnection):
            conn.set_cert(key_file=self.key_file,
                          cert_file=self.cert_file,
                          cert_reqs=self.cert_reqs,
                          ca_certs=self.ca_certs,
                          ca_cert_dir=self.ca_cert_dir,
                          assert_hostname=self.assert_hostname,
                          assert_fingerprint=self.assert_fingerprint)
            conn.ssl_version = self.ssl_version
        return conn
812650
private static void trustAllHosts() {
        // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[] {};
            }

            @Override
            public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }
        } };

        // Install the all-trusting trust manager
        try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
951416
public void initializeSystemPortProperties() {
		for (Connector connector : connectors) {
			if(connector.getProtocol().contains("HTTP")) {
				if(connector.getSecure()) {
					System.setProperty("org.mobicents.properties.sslPort", Integer.toString(connector.getPort()));
				} else {
					System.setProperty("org.mobicents.properties.httpPort", Integer.toString(connector.getPort()));
				}
			}
		}
	}
480722
def addPrivateCertificate(self, subjectName, existingCertificate=None):
        
        if existingCertificate is None:
            assert '@' not in subjectName, "Don't self-sign user certs!"
            mainDN = DistinguishedName(commonName=subjectName)
            mainKey = KeyPair.generate()
            mainCertReq = mainKey.certificateRequest(mainDN)
            mainCertData = mainKey.signCertificateRequest(
                mainDN, mainCertReq,
                lambda dn: True,
                self.genSerial(subjectName)
            )
            mainCert = mainKey.newCertificate(mainCertData)
        else:
            mainCert = existingCertificate
        self.localStore[subjectName] = mainCert
1249614
def activate(options = {})
      options = options.merge(
        user_name: @user_name,
        certificate_id: @id,
        status: "Active"
      )
      resp = @client.update_signing_certificate(options)
      resp.data
    end
1310942
def _init_client_authentication(
            self,
            client_certchain_file: Optional[str],
            client_key_file: Optional[str],
            client_key_type: OpenSslFileTypeEnum,
            client_key_password: str,
            ignore_client_authentication_requests: bool
    ) -> None:
        
        if client_certchain_file is not None and client_key_file is not None:
            self._use_private_key(client_certchain_file, client_key_file, client_key_type, client_key_password)

        if ignore_client_authentication_requests:
            if client_certchain_file:
                raise ValueError('Cannot enable both client_certchain_file and ignore_client_authentication_requests')

            self._ssl_ctx.set_client_cert_cb_NULL()
1008285
def generate_certificate(common_name, size=DEFAULT_KEY_SIZE):
    '''
        
    '''

    private_key_path = '{}/{}.key'.format(CERTIFICATES_PATH, common_name)
    certificate_path = '{}/{}.crt'.format(CERTIFICATES_PATH, common_name)
    if not os.path.isfile(certificate_path):
        print 'Create {}'.format(certificate_path)
        cmd = 'openssl req -x509 -nodes -newkey rsa:{size} -keyout {private_key_path} -out {certificate_path} -days 3650 -subj "/CN={common_name}"'.format(
            size=size, private_key_path=private_key_path,
            certificate_path=certificate_path, common_name=common_name)
        p = subprocess.Popen(cmd,
                             shell=True,
                             stdout=subprocess.PIPE,
                             close_fds=True)
        p.communicate()
        helpers.file_rights(private_key_path, mode=0400, uid=0, gid=0)
        helpers.file_rights(certificate_path, mode=0444, uid=0, gid=0)
    else:
        print 'Already exist: {}'.format(certificate_path)

    clean_links()
    make_links(common_name)
890023
def gen_cert_request(filepath, keyfile, config, silent=False):
    
    message = 'generate ssl certificate request'
    cmd = (
        'openssl req -new -key {} -out {} -subj "{}"'
        ' -extensions v3_req -config {}').format(
            keyfile, filepath, SUBJECT, config)
    call_openssl(cmd, message, silent)
985006
def _makeCertificate(key, email, _utcnow=datetime.utcnow):
    
    # Create a certificate for this key.
    cert = X509()
    cert.set_pubkey(key)

    # Set the subject.
    subject = cert.get_subject()
    subject.CN = u"Crypto 101 Client"
    subject.emailAddress = email

    # Expiration dates. Mandatory.
    now = _utcnow()
    start = now.replace(hour=0, minute=0, second=0)
    cert.set_notBefore(start.strftime(_ASN1_GENERALIZEDTIME_FORMAT))
    end = start.replace(year=start.year + 5)
    cert.set_notAfter(end.strftime(_ASN1_GENERALIZEDTIME_FORMAT))

    # Self-sign.
    cert.set_issuer(cert.get_subject())
    cert.sign(key, "sha512")

    return cert
172067
protected void init()
    {
        // "support for SSL"
        String handlerPkgs = System.getProperty("java.protocol.handler.pkgs");
        if ((handlerPkgs != null) && !(handlerPkgs.isEmpty())) {
            handlerPkgs = handlerPkgs + "|com.sun.net.ssl.internal.www.protocol";
        } else {
        	handlerPkgs = "com.sun.net.ssl.internal.www.protocol";
        }
        System.setProperty("java.protocol.handler.pkgs", handlerPkgs);

        java.security.Security
                .addProvider(new com.sun.net.ssl.internal.ssl.Provider());

        // Create custom EditorKit if needed
        if (swingBoxEditorKit == null) {
            swingBoxEditorKit = new SwingBoxEditorKit();
        }

        setEditable(false);
        setContentType("text/html");

        activateTooltip(true);

        Caret caret = getCaret();
        if (caret instanceof DefaultCaret)
        	((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }
203205
def configure(cert)
      cert.version = 2
      cert.serial = serial
      cert.subject = OpenSSL::X509::Name.parse(name)
      cert.issuer = cert.subject
      cert.public_key = key.public_key
      cert.not_before = days_ago(2)
      cert.not_after = days_from_now(2)
    end
1243873
public static void validateSslCertificate() {
        final NetworkHttpClient client = new NetworkHttpClient();
        final Request request = new Request(HttpMethod.GET, "https://api.twilio.com:8443");

        try {
            final Response response = client.makeRequest(request);

            if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) {
                throw new CertificateValidationException(
                    "Unexpected response from certificate endpoint", request, response
                );
            }
        } catch (final ApiException e) {
            throw new CertificateValidationException("Could not get response from certificate endpoint", request);
        }
    }
613189
def add_extensions(cert)
      factory = OpenSSL::X509::ExtensionFactory.new
      factory.issuer_certificate = Billy.certificate_authority.cert
      factory.subject_certificate = cert
      extensions.each do |ln_sn, value, critical|
        cert.add_extension(factory.create_extension(ln_sn, value, critical))
      end
    end