Creates a secure authorized gRPC channel.
976299
def secure_authorized_channel(
        credentials, target, ssl_credentials=None):
    """"""
    http_request = _request_factory()
    return google.auth.transport.grpc.secure_authorized_channel(
        credentials, http_request, target,
        ssl_credentials=ssl_credentials)
193658
def authorize(name=None, source_group_name=None,
              source_group_owner_id=None, ip_protocol=None,
              from_port=None, to_port=None, cidr_ip=None, group_id=None,
              source_group_group_id=None, region=None, key=None, keyid=None,
              profile=None, vpc_id=None, vpc_name=None, egress=False):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    group = _get_group(conn, name=name, vpc_id=vpc_id, vpc_name=vpc_name,
                       group_id=group_id, region=region, key=key, keyid=keyid,
                       profile=profile)
    if group:
        try:
            added = None
            if not egress:
                added = conn.authorize_security_group(
                    src_security_group_name=source_group_name,
                    src_security_group_owner_id=source_group_owner_id,
                    ip_protocol=ip_protocol, from_port=from_port, to_port=to_port,
                    cidr_ip=cidr_ip, group_id=group.id,
                    src_security_group_group_id=source_group_group_id)
            else:
                added = conn.authorize_security_group_egress(
                    ip_protocol=ip_protocol, from_port=from_port, to_port=to_port,
                    cidr_ip=cidr_ip, group_id=group.id,
                    src_group_id=source_group_group_id)
            if added:
                log.info('Added rule to security group %s with id %s',
                         group.name, group.id)
                return True
            else:
                msg = ('Failed to add rule to security group {0} with id {1}.'
                       .format(group.name, group.id))
                log.error(msg)
                return False
        except boto.exception.EC2ResponseError as e:
            # if we are trying to add the same rule then we are already in the desired state, return true
            if e.error_code == 'InvalidPermission.Duplicate':
                return True
            msg = ('Failed to add rule to security group {0} with id {1}.'
                   .format(group.name, group.id))
            log.error(msg)
            log.error(e)
            return False
    else:
        log.error('Failed to add rule to security group.')
        return False
731288
def secgroup_create(self, name, description):
        '''
        
        '''
        nt_ks = self.compute_conn
        nt_ks.security_groups.create(name, description)
        ret = {'name': name, 'description': description}
        return ret
794880
@ConditionalOnMissingBean(GrpcChannelFactory.class)
    @Bean
    public GrpcChannelFactory inProcessGrpcChannelFactory(final GrpcChannelsProperties properties,
            final GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
            final List<GrpcChannelConfigurer> channelConfigurers) {
        return new InProcessChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers);
    }
945665
def insecure_channel(target, options=None, *, loop=None, executor=None,
                    standalone_pool_for_streaming=False):
    
    return Channel(_grpc.insecure_channel(target, options), loop, executor, standalone_pool_for_streaming)
1101672
def createClientCertificate(self, name, noPass = True, keyLength = 2048, days = 375):
        
        if not name:
            raise ValueError('Require name')
        configPath, keyPath, csrPath, certPath = \
                os.path.join(self.basePath, self.FILE_CONFIG), \
                os.path.join(self.basePath, self.DIR_PRIVATE, '%s.key.pem' % name), \
                os.path.join(self.basePath, self.DIR_CSR, '%s.csr.pem' % name), \
                os.path.join(self.basePath, self.DIR_CERTS, '%s.cert.pem' % name)
        if os.path.isfile(keyPath):
            raise ValueError('Key file exists at [%s]' % keyPath)
        if os.path.isfile(csrPath):
            raise ValueError('CSR file exists at [%s]' % csrPath)
        if os.path.isfile(certPath):
            raise ValueError('Certificate file exists at [%s]' % certPath)
        # Generate the key
        if subprocess.call([ 'openssl', 'genrsa', '-aes256', '-out', keyPath, str(keyLength) ] if not noPass else [ 'openssl', 'genrsa', '-out', keyPath, str(keyLength) ]) != 0:
            raise ValueError('Failed to create key')
        # Generate the csr
        if subprocess.call([ 'openssl', 'req', '-config', configPath, '-key', keyPath, '-new', '-sha256', '-out', csrPath ]) != 0:
            raise ValueError('Failed to create CSR')
        # Generate the certificate
        if subprocess.call([ 'openssl', 'ca', '-config', configPath, '-extensions', 'usr_cert', '-days', str(days), '-notext', '-md', 'sha256', '-in', csrPath, '-out', certPath ]) != 0:
            raise ValueError('Failed to create certificate')
261881
@Handler(channels = EncryptedChannel.class)
    public void onAccepted(Accepted event, IOSubchannel encryptedChannel) {
        new PlainChannel(event, encryptedChannel);
    }
1130938
function main() {
  var server = new grpc.Server();
  server.addService(services.GreeterService, {sayHello: sayHello});
  server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  server.start();
}
138903
def create_subkey(primary_bytes, subkey, signer_func, secret_bytes=b''):
    """"""
    subkey_packet = protocol.packet(tag=(7 if secret_bytes else 14),
                                    blob=(subkey.data() + secret_bytes))
    packets = list(decode.parse_packets(io.BytesIO(primary_bytes)))
    primary, user_id, signature = packets[:3]

    data_to_sign = primary['_to_hash'] + subkey.data_to_hash()

    if subkey.ecdh:
        embedded_sig = None
    else:
        # Primary Key Binding Signature
        hashed_subpackets = [
            protocol.subpacket_time(subkey.created)]  # signature time
        unhashed_subpackets = [
            protocol.subpacket(16, subkey.key_id())]  # issuer key id
        embedded_sig = protocol.make_signature(
            signer_func=signer_func,
            data_to_sign=data_to_sign,
            public_algo=subkey.algo_id,
            sig_type=0x19,
            hashed_subpackets=hashed_subpackets,
            unhashed_subpackets=unhashed_subpackets)

    # Subkey Binding Signature

    # Key flags: https://tools.ietf.org/html/rfc4880#section-5.2.3.21
    # (certify & sign)                   (encrypt)
    flags = (2) if (not subkey.ecdh) else (4 | 8)

    hashed_subpackets = [
        protocol.subpacket_time(subkey.created),  # signature time
        protocol.subpacket_byte(0x1B, flags)]

    unhashed_subpackets = []
    unhashed_subpackets.append(protocol.subpacket(16, primary['key_id']))
    if embedded_sig is not None:
        unhashed_subpackets.append(protocol.subpacket(32, embedded_sig))
    unhashed_subpackets.append(protocol.CUSTOM_SUBPACKET)

    if not decode.has_custom_subpacket(signature):
        signer_func = keyring.create_agent_signer(user_id['value'])

    signature = protocol.make_signature(
        signer_func=signer_func,
        data_to_sign=data_to_sign,
        public_algo=primary['algo'],
        sig_type=0x18,
        hashed_subpackets=hashed_subpackets,
        unhashed_subpackets=unhashed_subpackets)
    sign_packet = protocol.packet(tag=2, blob=signature)
    return primary_bytes + subkey_packet + sign_packet
1336095
def _generate_auth_token(self, channel_name):
        
        subject = "{}:{}".format(self.connection.socket_id, channel_name)
        h = hmac.new(self.secret_as_bytes, subject.encode('utf-8'), hashlib.sha256)
        auth_key = "{}:{}".format(self.key, h.hexdigest())

        return auth_key
377926
public static AltsProtocolNegotiator createServerNegotiator(
      final TsiHandshakerFactory handshakerFactory, final LazyChannel lazyHandshakerChannel) {
    final class ServerAltsProtocolNegotiator extends AltsProtocolNegotiator {

      @Override
      public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
        TsiHandshaker handshaker = handshakerFactory.newHandshaker(/*authority=*/ null);
        return new BufferUntilAltsNegotiatedHandler(
            grpcHandler,
            new TsiHandshakeHandler(new NettyTsiHandshaker(handshaker)),
            new TsiFrameHandler());
      }

      @Override
      public void close() {
        logger.finest("ALTS Server ProtocolNegotiator Closed");
        lazyHandshakerChannel.close();
      }
    }

    return new ServerAltsProtocolNegotiator();
  }
640278
public byte[] createSecret (PublicKeyCredentials pkcred, PrivateKey key, int length)
    {
        _data = new AuthResponseData();
        byte[] clientSecret = pkcred.getSecret(key);
        if (clientSecret == null) {
            _data.code = FAILED_TO_SECURE;
            return null;
        }
        byte[] secret = SecureUtil.createRandomKey(length);
        _data.code = StringUtil.hexlate(SecureUtil.xorBytes(secret, clientSecret));
        return secret;
    }
1254639
def _create(self, common_name, public_key_algorithm='rsa',
            signature_algorithm='rsa_sha_512', key_length=2048,
            signing_ca=None):
        
        if signing_ca is None:
            signing_ca = VPNCertificateCA.objects.filter('Internal RSA').first()
        
        cert_auth = element_resolver(signing_ca)
        
        return ElementCreator(
            GatewayCertificate,
            exception=CertificateError,
            href=self.internal_gateway.get_relation('generate_certificate'),
            json={
                'common_name': common_name,
                'public_key_algorithm': public_key_algorithm,
                'signature_algorithm': signature_algorithm,
                'public_key_length': key_length,
                'certificate_authority_href': cert_auth})
746185
public Peer newPeer(String name, String grpcURL) throws InvalidArgumentException {
        clientCheck();
        return Peer.createNewInstance(name, grpcURL, null);
    }
1247640
function createOnAuthStateChangedChannel() {
  const auth = this.app.auth();
  const channel = eventChannel(emit =>
    auth.onAuthStateChanged(user => emit({ user })),
  );
  return channel;
}
855045
def create(gandi, vhost, paas, ssl, private_key, alter_zone, poll_cert,
           background):
    
    if not gandi.hostedcert.activate_ssl(vhost, ssl, private_key, poll_cert):
        return

    paas_info = gandi.paas.info(paas)
    result = gandi.vhost.create(paas_info, vhost, alter_zone, background)

    if background:
        gandi.pretty_echo(result)

    return result
1294566
public GrpcChannel build() throws AlluxioStatusException {
    ManagedChannel underlyingChannel =
        GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(mChannelKey,
            mConfiguration.getMs(PropertyKey.NETWORK_CONNECTION_HEALTH_CHECK_TIMEOUT_MS),
            mConfiguration.getMs(PropertyKey.MASTER_GRPC_CHANNEL_SHUTDOWN_TIMEOUT));
    try {
      Channel clientChannel = underlyingChannel;

      if (mAuthenticateChannel) {
        // Create channel authenticator based on provided content.
        ChannelAuthenticator channelAuthenticator;
        if (mUseSubject) {
          channelAuthenticator = new ChannelAuthenticator(mParentSubject, mConfiguration);
        } else {
          channelAuthenticator =
              new ChannelAuthenticator(mUserName, mPassword, mImpersonationUser,
                  mConfiguration.getEnum(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.class),
                  mConfiguration.getMs(PropertyKey.MASTER_GRPC_CHANNEL_AUTH_TIMEOUT));
        }
        // Get an authenticated wrapper channel over given managed channel.
        clientChannel = channelAuthenticator.authenticate(mServerAddress, underlyingChannel);
      }
      // Create the channel after authentication with the target.
      return new GrpcChannel(mChannelKey, clientChannel,
          mConfiguration.getMs(PropertyKey.MASTER_GRPC_CHANNEL_SHUTDOWN_TIMEOUT));
    } catch (Exception exc) {
      // Release the managed channel to the pool before throwing.
      GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(mChannelKey,
          mConfiguration.getMs(PropertyKey.MASTER_GRPC_CHANNEL_SHUTDOWN_TIMEOUT));
      throw exc;
    }
  }