pijul_org / thrussh

Removing the dependency on hex

By pmeunier on February 29, 2020
signed by pmeunier.
68kZLWjksxAV7CeNWwtF4Bp92ocHKST8psqtMNUyQN1ksaLfyR6pcQskvdPBVS6CfwRnz7y6uiTNfKgodCnGqXM2
This patch is in the following branches:
master
583
584
585
                    b"window-change" => {
                        let col_width = r.read_u32()?;
35
36

futures = "0.3"
cryptovec = "0.5.0"
hex = "0.4"
2
3



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
use crate::key;
use crate::Error;
use data_encoding::BASE64_MIME;
use hex::FromHex;
use hex::FromHex;
use data_encoding::{HEXLOWER_PERMISSIVE, BASE64_MIME};
use openssl::rsa::Rsa;
use std::io::Write;

mod openssh;
pub use self::openssh::*;

mod pkcs5;
pub use self::pkcs5::*;

mod pkcs8;

const AES_128_CBC: &'static str = "DEK-Info: AES-128-CBC,";

#[derive(Clone, Copy, Debug)]
/// AES encryption key.
pub enum Encryption {
    /// Key for AES128
    Aes128Cbc([u8; 16]),
    /// Key for AES256
    Aes256Cbc([u8; 16]),
}

#[derive(Clone, Debug)]
enum Format {
    Rsa,
    Openssh,
    Pkcs5Encrypted(Encryption),
    Pkcs8Encrypted,
    Pkcs8,
}

/// Decode a secret key, possibly deciphering it with the supplied
/// password.
pub fn decode_secret_key(
    secret: &str,
    password: Option<&[u8]>,
) -> Result<key::KeyPair, failure::Error> {
    let mut format = None;
    let secret = {
        let mut started = false;
        let mut sec = String::new();
        for l in secret.lines() {
            if started == true {
                if l.starts_with("-----END ") {
                    break;
                }
                if l.chars().all(is_base64_char) {
                    sec.push_str(l)
                } else if l.starts_with(AES_128_CBC) {
                    let iv_: Vec<u8> = FromHex::from_hex(l.split_at(AES_128_CBC.len()).1)?;
                    let iv_: Vec<u8> = HEXLOWER_PERMISSIVE.decode(l.split_at(AES_128_CBC.len()).1.as_bytes())?;
                    if iv_.len() != 16 {
84
85







#[derive(Debug, Fail)]
pub enum Error {
    // IO(std::io::Error),
    // Utf8(std::str::Utf8Error),
    // OpenSSL(openssl::error::Error),
    // OpenSSLStack(openssl::error::ErrorStack),
    // Hex(hex::FromHexError),
    // Yasna(yasna::ASN1Error),
    // Base64(data_encoding::DecodeError),