public override void SaveToFile(string fullName) { Directory.CreateDirectory(Path.GetDirectoryName(fullName)); switch (ContentTypeUtils.FromExtension(Path.GetExtension(fullName))) { case ContentType.KeyVaultSecret: // Serialize the entire secret as encrypted JSON for current user File.WriteAllText(fullName, new KeyVaultSecretFile(_secret).Serialize()); break; case ContentType.KeyVaultCertificate: throw new InvalidOperationException("One can't save key vault secret as key vault certificate"); case ContentType.KeyVaultLink: File.WriteAllText(fullName, GetLinkAsInternetShortcut()); break; case ContentType.Certificate: File.WriteAllBytes(fullName, CertificateValueObject.FromValue(Value).Certificate.Export(X509ContentType.Cert)); break; case ContentType.Pkcs12: File.WriteAllBytes(fullName, Convert.FromBase64String(CertificateValueObject.FromValue(Value).Data)); break; default: File.WriteAllText(fullName, Value); break; } }
public override DataObject GetClipboardValue() { var dataObj = base.GetClipboardValue(); // We use SetData() and not SetText() to support correctly empty string "" as a value dataObj.SetData(DataFormats.UnicodeText, ContentType.IsCertificate() ? CertificateValueObject.FromValue(Value)?.Password : Value); return(dataObj); }
private void RefreshCertificate(CertificateValueObject cvo) { _certificateObj = cvo; if (_certificateObj != null) { _certificateObj.FillTagsAndExpiration(PropertyObject); uxTextBoxValue.Text = _certificateObj.ToValue(PropertyObject.SecretKind.CertificateFormat); uxTextBoxValue.Refresh(); } ToggleCertificateMode(_certificateObj != null); }
private void AutoDetectSecretKind() { SecretKind autoDetectSecretKind = (SecretKind)uxMenuSecretKind.Items[0]; // Default is the first one which is always Custom foreach (var item in uxMenuSecretKind.Items) // Auto detect 'last' secret kind based on the name only { SecretKind sk = (SecretKind)item; autoDetectSecretKind = sk.NameRegex.IsMatch(uxTextBoxName.Text) ? sk : autoDetectSecretKind; } // Apply last found secret kind, only when both Content Type and SecretKind are certificate or both not, otherwise fallback to Custom (the first one) if ((!PropertyObject.ContentType.IsCertificate() || !autoDetectSecretKind.IsCertificate) && (PropertyObject.ContentType.IsCertificate() || autoDetectSecretKind.IsCertificate)) { autoDetectSecretKind = (SecretKind)uxMenuSecretKind.Items[0]; } _certificateObj = PropertyObject.ContentType.IsCertificate() ? CertificateValueObject.FromValue(uxTextBoxValue.Text) : null; autoDetectSecretKind?.PerformClick(); }
private void AutoDetectSecretKind() { SecretKind defaultSecretKind = TryGetDefaultSecretKind(); // Default is the first one which is always Custom SecretKind autoDetectSecretKind = new SecretKind(defaultSecretKind.Alias); TagItem currentSKTag = PropertyObject.Tags.GetOrNull(new TagItem(Consts.SecretKindKey, "")); bool shouldAddNew = true; // Read the CustomTags and determine the SecretKind foreach (SecretKind sk in uxMenuSecretKind.Items) // Auto detect 'last' secret kind based on the name only { if (currentSKTag == null) { autoDetectSecretKind = defaultSecretKind; shouldAddNew = false; break; } // If the current Secret Kind is in the list of menu items, if (currentSKTag.Value == sk.Alias) { autoDetectSecretKind = sk; shouldAddNew = false; break; } } if (shouldAddNew) { autoDetectSecretKind = new SecretKind(currentSKTag.Value); uxMenuSecretKind.Items.Add(autoDetectSecretKind); } // Apply last found secret kind, only when both Content Type and SecretKind are certificate or both not, otherwise fallback to Custom (the first one) if ((!PropertyObject.ContentType.IsCertificate() || !autoDetectSecretKind.IsCertificate) && (PropertyObject.ContentType.IsCertificate() || autoDetectSecretKind.IsCertificate)) { autoDetectSecretKind = TryGetDefaultSecretKind(); } _certificateObj = PropertyObject.ContentType.IsCertificate() ? CertificateValueObject.FromValue(uxTextBoxValue.Text) : null; autoDetectSecretKind?.PerformClick(); }