'  
'   Rebex Sample Code License
' 
'   Copyright 2025, REBEX CR s.r.o.
'   All rights reserved.
'   https://www.rebex.net/
' 
'   Permission to use, copy, modify, and/or distribute this software for any
'   purpose with or without fee is hereby granted.
' 
'   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
'   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
'   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
'   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
'   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
'   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
'   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
'   OTHER DEALINGS IN THE SOFTWARE.
' 

Imports System.Drawing
Imports System.Windows.Forms
Imports Rebex.Security.Certificates
Imports Rebex.Net

Public Partial Class ResolveInvalidKeyDialog
    Inherits Form
    Public Sub New(dialogMode As ResolveDialogMode, failureReason As String, hashAlgorithm As SignatureHashAlgorithm, storedKeyAlgorithm As SshHostKeyAlgorithm, storedFingerprint As String, serverKeyAlgorithm As SshHostKeyAlgorithm, _
        serverKeyFingerprint As String)
        InitializeComponent()
        lblReasons.Text = failureReason
        lblHashAlgorighm.Text = hashAlgorithm.ToString()
        lblServerKeyAlgorithm.Text = serverKeyAlgorithm.ToString()
        lblServerKeyFingerprint.Text = serverKeyFingerprint

        If dialogMode = ResolveDialogMode.EntryDiffer Then
            lblReasons.ForeColor = Color.Red
            lblStoredKeyAlgorithm.Text = storedKeyAlgorithm.ToString()
            lblStoredFingerprint.Text = storedFingerprint
        Else
            lblStoredKeyAlgorithm.Visible = False
            lblStoredFingerprint.Visible = False

            lblStoredKeyAlgorithmLabel.Visible = False
            lblStoredKeyFingerprintLabel.Visible = False
        End If
    End Sub

    Public Function GetChoosenMode() As KeyVerifyingMode
        If DialogResult <> DialogResult.OK Then
            Throw New InvalidOperationException("Cannot resolve choosen mode when the dialog has not been confirmed by the OK button.")
        End If

        If rbAcceptAny.Checked Then
            Return KeyVerifyingMode.AcceptAnyKey
        End If
        If rbStoreLocally.Checked Then
            Return KeyVerifyingMode.LocalyStoredFingerprint
        End If
        If rbReject.Checked Then
            Return KeyVerifyingMode.RejectKey
        End If

        Throw New InvalidOperationException("Unexpected state when resolving CertfificateVerifyingMode.")

    End Function

    Private Sub ResolveInvalidCertficiateDialog_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated
        ' recalculate height
        Dim delta As Integer = Me.Height - pnlLayout.Height
        pnlLayout.Size = New Size(pnlLayout.Width, pnlButtons.Top + pnlButtons.Height)
        Me.Size = New Size(Me.Width, pnlLayout.Height + delta)
        Me.MinimumSize = New Size(Me.MinimumSize.Width, Me.Height)
    End Sub

    ''' <summary>
    ''' Required designer variable.
    ''' </summary>
    Private components As System.ComponentModel.IContainer = Nothing

    ''' <summary>
    ''' Clean up any resources being used.
    ''' </summary>
    ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    Protected Overrides Sub Dispose(disposing As Boolean)
        If disposing AndAlso (components IsNot Nothing) Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    #Region "Windows Form Designer generated code"

    ''' <summary>
    ''' Required method for Designer support - do not modify
    ''' the contents of this method with the code editor.
    ''' </summary>
    Private Sub InitializeComponent()
        Me.label1 = New System.Windows.Forms.Label()
        Me.pnlLayout = New System.Windows.Forms.Panel()
        Me.rbReject = New System.Windows.Forms.RadioButton()
        Me.pnlButtons = New System.Windows.Forms.Panel()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.btnOk = New System.Windows.Forms.Button()
        Me.rbAcceptAny = New System.Windows.Forms.RadioButton()
        Me.rbStoreLocally = New System.Windows.Forms.RadioButton()
        Me.label3 = New System.Windows.Forms.Label()
        Me.pnlDetails = New System.Windows.Forms.Panel()
        Me.lblServerKeyAlgorithm = New System.Windows.Forms.Label()
        Me.label6 = New System.Windows.Forms.Label()
        Me.lblServerKeyFingerprint = New System.Windows.Forms.Label()
        Me.label11 = New System.Windows.Forms.Label()
        Me.lblStoredKeyAlgorithm = New System.Windows.Forms.Label()
        Me.lblStoredKeyFingerprintLabel = New System.Windows.Forms.Label()
        Me.label10 = New System.Windows.Forms.Label()
        Me.lblStoredFingerprint = New System.Windows.Forms.Label()
        Me.lblHashAlgorighm = New System.Windows.Forms.Label()
        Me.lblStoredKeyAlgorithmLabel = New System.Windows.Forms.Label()
        Me.label2 = New System.Windows.Forms.Label()
        Me.lblReasons = New System.Windows.Forms.Label()
        Me.pnlLayout.SuspendLayout()
        Me.pnlButtons.SuspendLayout()
        Me.pnlDetails.SuspendLayout()
        Me.SuspendLayout()
        '
        'label1
        '
        Me.label1.AutoSize = True
        Me.label1.Dock = System.Windows.Forms.DockStyle.Top
        Me.label1.Location = New System.Drawing.Point(0, 0)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(124, 13)
        Me.label1.TabIndex = 0
        Me.label1.Text = "Server key is not trusted:"
        '
        'pnlLayout
        '
        Me.pnlLayout.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlLayout.Controls.Add(Me.rbReject)
        Me.pnlLayout.Controls.Add(Me.pnlButtons)
        Me.pnlLayout.Controls.Add(Me.rbAcceptAny)
        Me.pnlLayout.Controls.Add(Me.rbStoreLocally)
        Me.pnlLayout.Controls.Add(Me.label3)
        Me.pnlLayout.Controls.Add(Me.pnlDetails)
        Me.pnlLayout.Controls.Add(Me.label2)
        Me.pnlLayout.Controls.Add(Me.lblReasons)
        Me.pnlLayout.Controls.Add(Me.label1)
        Me.pnlLayout.Location = New System.Drawing.Point(12, 12)
        Me.pnlLayout.Name = "pnlLayout"
        Me.pnlLayout.Size = New System.Drawing.Size(490, 386)
        Me.pnlLayout.TabIndex = 1
        '
        'rbReject
        '
        Me.rbReject.AutoSize = True
        Me.rbReject.Dock = System.Windows.Forms.DockStyle.Top
        Me.rbReject.Location = New System.Drawing.Point(0, 309)
        Me.rbReject.Name = "rbReject"
        Me.rbReject.Padding = New System.Windows.Forms.Padding(10, 0, 10, 0)
        Me.rbReject.Size = New System.Drawing.Size(490, 17)
        Me.rbReject.TabIndex = 7
        Me.rbReject.Text = "Reject the server key"
        Me.rbReject.UseVisualStyleBackColor = True
        '
        'pnlButtons
        '
        Me.pnlButtons.Controls.Add(Me.btnCancel)
        Me.pnlButtons.Controls.Add(Me.btnOk)
        Me.pnlButtons.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.pnlButtons.Location = New System.Drawing.Point(0, 353)
        Me.pnlButtons.Name = "pnlButtons"
        Me.pnlButtons.Size = New System.Drawing.Size(490, 33)
        Me.pnlButtons.TabIndex = 8
        '
        'btnCancel
        '
        Me.btnCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(415, 6)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 11
        Me.btnCancel.Text = "Cancel"
        Me.btnCancel.UseVisualStyleBackColor = True
        '
        'btnOk
        '
        Me.btnOk.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOk.Location = New System.Drawing.Point(334, 6)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.Size = New System.Drawing.Size(75, 23)
        Me.btnOk.TabIndex = 10
        Me.btnOk.Text = "OK"
        Me.btnOk.UseVisualStyleBackColor = True
        '
        'rbAcceptAny
        '
        Me.rbAcceptAny.AutoSize = True
        Me.rbAcceptAny.CheckAlign = System.Drawing.ContentAlignment.TopLeft
        Me.rbAcceptAny.Dock = System.Windows.Forms.DockStyle.Top
        Me.rbAcceptAny.Location = New System.Drawing.Point(0, 292)
        Me.rbAcceptAny.Name = "rbAcceptAny"
        Me.rbAcceptAny.Padding = New System.Windows.Forms.Padding(10, 0, 10, 0)
        Me.rbAcceptAny.Size = New System.Drawing.Size(490, 17)
        Me.rbAcceptAny.TabIndex = 6
        Me.rbAcceptAny.Text = "Ignore the failure and accept the key"
        Me.rbAcceptAny.UseVisualStyleBackColor = True
        '
        'rbStoreLocally
        '
        Me.rbStoreLocally.AutoSize = True
        Me.rbStoreLocally.CheckAlign = System.Drawing.ContentAlignment.TopLeft
        Me.rbStoreLocally.Checked = True
        Me.rbStoreLocally.Dock = System.Windows.Forms.DockStyle.Top
        Me.rbStoreLocally.Location = New System.Drawing.Point(0, 275)
        Me.rbStoreLocally.Name = "rbStoreLocally"
        Me.rbStoreLocally.Padding = New System.Windows.Forms.Padding(10, 0, 10, 0)
        Me.rbStoreLocally.Size = New System.Drawing.Size(490, 17)
        Me.rbStoreLocally.TabIndex = 5
        Me.rbStoreLocally.TabStop = True
        Me.rbStoreLocally.Text = "Accept the server key (and remember it)"
        Me.rbStoreLocally.TextAlign = System.Drawing.ContentAlignment.TopLeft
        Me.rbStoreLocally.UseVisualStyleBackColor = True
        '
        'label3
        '
        Me.label3.AutoSize = True
        Me.label3.Dock = System.Windows.Forms.DockStyle.Top
        Me.label3.Location = New System.Drawing.Point(0, 252)
        Me.label3.Name = "label3"
        Me.label3.Padding = New System.Windows.Forms.Padding(0, 5, 0, 5)
        Me.label3.Size = New System.Drawing.Size(204, 23)
        Me.label3.TabIndex = 4
        Me.label3.Text = "You can solve it by one of following ways:"
        '
        'pnlDetails
        '
        Me.pnlDetails.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.pnlDetails.Controls.Add(Me.lblServerKeyAlgorithm)
        Me.pnlDetails.Controls.Add(Me.label6)
        Me.pnlDetails.Controls.Add(Me.lblServerKeyFingerprint)
        Me.pnlDetails.Controls.Add(Me.label11)
        Me.pnlDetails.Controls.Add(Me.lblStoredKeyAlgorithm)
        Me.pnlDetails.Controls.Add(Me.lblStoredKeyFingerprintLabel)
        Me.pnlDetails.Controls.Add(Me.label10)
        Me.pnlDetails.Controls.Add(Me.lblStoredFingerprint)
        Me.pnlDetails.Controls.Add(Me.lblHashAlgorighm)
        Me.pnlDetails.Controls.Add(Me.lblStoredKeyAlgorithmLabel)
        Me.pnlDetails.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlDetails.Location = New System.Drawing.Point(0, 82)
        Me.pnlDetails.Name = "pnlDetails"
        Me.pnlDetails.Padding = New System.Windows.Forms.Padding(10)
        Me.pnlDetails.Size = New System.Drawing.Size(490, 170)
        Me.pnlDetails.TabIndex = 3
        '
        'lblServerKeyAlgorithm
        '
        Me.lblServerKeyAlgorithm.Location = New System.Drawing.Point(116, 37)
        Me.lblServerKeyAlgorithm.Name = "lblServerKeyAlgorithm"
        Me.lblServerKeyAlgorithm.Size = New System.Drawing.Size(143, 17)
        Me.lblServerKeyAlgorithm.TabIndex = 13
        Me.lblServerKeyAlgorithm.Text = "DSS"
        '
        'label6
        '
        Me.label6.AutoSize = True
        Me.label6.Location = New System.Drawing.Point(0, 54)
        Me.label6.Name = "label6"
        Me.label6.Size = New System.Drawing.Size(110, 13)
        Me.label6.TabIndex = 12
        Me.label6.Text = "Server key fingerprint:"
        '
        'lblServerKeyFingerprint
        '
        Me.lblServerKeyFingerprint.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblServerKeyFingerprint.Location = New System.Drawing.Point(116, 54)
        Me.lblServerKeyFingerprint.Name = "lblServerKeyFingerprint"
        Me.lblServerKeyFingerprint.Size = New System.Drawing.Size(371, 42)
        Me.lblServerKeyFingerprint.TabIndex = 11
        Me.lblServerKeyFingerprint.Text = "AB-01-F8-etc."
        '
        'label11
        '
        Me.label11.AutoSize = True
        Me.label11.Location = New System.Drawing.Point(0, 37)
        Me.label11.Name = "label11"
        Me.label11.Size = New System.Drawing.Size(106, 13)
        Me.label11.TabIndex = 10
        Me.label11.Text = "Server key algorithm:"
        '
        'lblStoredKeyAlgorithm
        '
        Me.lblStoredKeyAlgorithm.Location = New System.Drawing.Point(116, 106)
        Me.lblStoredKeyAlgorithm.Name = "lblStoredKeyAlgorithm"
        Me.lblStoredKeyAlgorithm.Size = New System.Drawing.Size(143, 17)
        Me.lblStoredKeyAlgorithm.TabIndex = 9
        Me.lblStoredKeyAlgorithm.Text = "DSS"
        '
        'lblStoredKeyFingerprintLabel
        '
        Me.lblStoredKeyFingerprintLabel.AutoSize = True
        Me.lblStoredKeyFingerprintLabel.Location = New System.Drawing.Point(0, 123)
        Me.lblStoredKeyFingerprintLabel.Name = "lblStoredKeyFingerprintLabel"
        Me.lblStoredKeyFingerprintLabel.Size = New System.Drawing.Size(110, 13)
        Me.lblStoredKeyFingerprintLabel.TabIndex = 8
        Me.lblStoredKeyFingerprintLabel.Text = "Stored key fingerprint:"
        '
        'label10
        '
        Me.label10.AutoSize = True
        Me.label10.Location = New System.Drawing.Point(0, 10)
        Me.label10.Name = "label10"
        Me.label10.Size = New System.Drawing.Size(112, 13)
        Me.label10.TabIndex = 8
        Me.label10.Text = "Used hash algorigthm:"
        '
        'lblStoredFingerprint
        '
        Me.lblStoredFingerprint.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblStoredFingerprint.Location = New System.Drawing.Point(116, 123)
        Me.lblStoredFingerprint.Name = "lblStoredFingerprint"
        Me.lblStoredFingerprint.Size = New System.Drawing.Size(371, 42)
        Me.lblStoredFingerprint.TabIndex = 7
        Me.lblStoredFingerprint.Text = "AB-01-F8-etc."
        '
        'lblHashAlgorighm
        '
        Me.lblHashAlgorighm.Location = New System.Drawing.Point(116, 10)
        Me.lblHashAlgorighm.Name = "lblHashAlgorighm"
        Me.lblHashAlgorighm.Size = New System.Drawing.Size(143, 17)
        Me.lblHashAlgorighm.TabIndex = 7
        Me.lblHashAlgorighm.Text = "SHA-1"
        '
        'lblStoredKeyAlgorithmLabel
        '
        Me.lblStoredKeyAlgorithmLabel.AutoSize = True
        Me.lblStoredKeyAlgorithmLabel.Location = New System.Drawing.Point(0, 106)
        Me.lblStoredKeyAlgorithmLabel.Name = "lblStoredKeyAlgorithmLabel"
        Me.lblStoredKeyAlgorithmLabel.Size = New System.Drawing.Size(106, 13)
        Me.lblStoredKeyAlgorithmLabel.TabIndex = 6
        Me.lblStoredKeyAlgorithmLabel.Text = "Stored key algorithm:"
        '
        'label2
        '
        Me.label2.AutoSize = True
        Me.label2.Dock = System.Windows.Forms.DockStyle.Top
        Me.label2.Location = New System.Drawing.Point(0, 64)
        Me.label2.Name = "label2"
        Me.label2.Padding = New System.Windows.Forms.Padding(0, 0, 0, 5)
        Me.label2.Size = New System.Drawing.Size(42, 18)
        Me.label2.TabIndex = 2
        Me.label2.Text = "Details:"
        '
        'lblReasons
        '
        Me.lblReasons.Dock = System.Windows.Forms.DockStyle.Top
        Me.lblReasons.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(238, Byte))
        Me.lblReasons.Location = New System.Drawing.Point(0, 13)
        Me.lblReasons.Name = "lblReasons"
        Me.lblReasons.Padding = New System.Windows.Forms.Padding(10)
        Me.lblReasons.Size = New System.Drawing.Size(490, 51)
        Me.lblReasons.TabIndex = 1
        Me.lblReasons.Text = "reasons..."
        '
        'ResolveInvalidKeyDialog
        '
        Me.AcceptButton = Me.btnOk
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = New System.Drawing.Size(514, 408)
        Me.Controls.Add(Me.pnlLayout)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.MinimumSize = New System.Drawing.Size(530, 39)
        Me.Name = "ResolveInvalidKeyDialog"
        Me.ShowIcon = False
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Untrusted Server Key"
        Me.pnlLayout.ResumeLayout(False)
        Me.pnlLayout.PerformLayout()
        Me.pnlButtons.ResumeLayout(False)
        Me.pnlDetails.ResumeLayout(False)
        Me.pnlDetails.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

    #End Region

    Private label1 As System.Windows.Forms.Label
    Private pnlLayout As System.Windows.Forms.Panel
    Private btnOk As System.Windows.Forms.Button
    Private btnCancel As System.Windows.Forms.Button
    Private lblReasons As System.Windows.Forms.Label
    Private pnlDetails As System.Windows.Forms.Panel
    Private label2 As System.Windows.Forms.Label
    Private rbAcceptAny As System.Windows.Forms.RadioButton
    Private label3 As System.Windows.Forms.Label
    Private rbStoreLocally As System.Windows.Forms.RadioButton
    Private rbReject As System.Windows.Forms.RadioButton
    Private pnlButtons As System.Windows.Forms.Panel
    Private lblStoredKeyAlgorithmLabel As System.Windows.Forms.Label
    Private label10 As System.Windows.Forms.Label
    Private lblHashAlgorighm As System.Windows.Forms.Label
    Private lblStoredFingerprint As System.Windows.Forms.Label
    Private lblStoredKeyFingerprintLabel As System.Windows.Forms.Label
    Private lblStoredKeyAlgorithm As System.Windows.Forms.Label
    Private lblServerKeyAlgorithm As System.Windows.Forms.Label
    Private label6 As System.Windows.Forms.Label
    Private lblServerKeyFingerprint As System.Windows.Forms.Label
    Private label11 As System.Windows.Forms.Label
End Class
