示例#1
0
文件: sshkey.go 项目: crohling/kops
// toDER gets the DER encoding of the SSH public key
// Annoyingly, the ssh code wraps the actual crypto keys, so we have to use reflection tricks
func toDER(pubkey ssh.PublicKey) ([]byte, error) {
	pubkeyValue := reflect.ValueOf(pubkey)
	typeName := utils.BuildTypeName(pubkeyValue.Type())

	var cryptoKey crypto.PublicKey
	switch typeName {
	case "*rsaPublicKey":
		var rsaPublicKey *rsa.PublicKey
		targetType := reflect.ValueOf(rsaPublicKey).Type()
		rsaPublicKey = pubkeyValue.Convert(targetType).Interface().(*rsa.PublicKey)
		cryptoKey = rsaPublicKey

	case "*dsaPublicKey":
		var dsaPublicKey *dsa.PublicKey
		targetType := reflect.ValueOf(dsaPublicKey).Type()
		dsaPublicKey = pubkeyValue.Convert(targetType).Interface().(*dsa.PublicKey)
		cryptoKey = dsaPublicKey

	default:
		return nil, fmt.Errorf("Unknown type for SSH PublicKey; cannot compute fingerprint: %q", typeName)
	}

	der, err := x509.MarshalPKIXPublicKey(cryptoKey)
	if err != nil {
		return nil, fmt.Errorf("error marshalling SSH public key: %v", err)
	}
	return der, nil
}
示例#2
0
文件: service.go 项目: crohling/kops
func (p *Service) GetDependencies(tasks map[string]fi.Task) []fi.Task {
	var deps []fi.Task
	for _, v := range tasks {
		// We assume that services depend on basically everything
		typeName := utils.BuildTypeName(reflect.TypeOf(v))
		switch typeName {
		case "*CopyAssetTask", "*File", "*Package", "*Sysctl", "*UpdatePackages", "*User", "*Disk":
			deps = append(deps, v)
		case "*Service":
		// ignore
		default:
			glog.Warningf("Unhandled type name in Service::GetDependencies: %q", typeName)
			deps = append(deps, v)
		}
	}
	return deps
}