<commit_before># --
# SMIME.t - SMIME tests
# Copyright (C) 2001-2008 OTRS AG, http://otrs.org/
# --
# $Id: SMIME.t,v 1.4 2008-05-08 09:35:57 mh Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl-2.0.txt.
# --

use strict;
use warnings;

use Kernel::System::Crypt;

use vars qw($Self);

my $HomeDir = $Self->{ConfigObject}->Get('Home');

# set config
$Self->{ConfigObject}->Set( Key => 'SMIME', Value => 1 );

#$Self->{ConfigObject}->Set(
#    Key => 'SMIME::CertPath', Value => "$HomeDir/var/ssl/certs"
#);
#$Self->{ConfigObject}->Set(
#    Key => 'SMIME::PrivatePath', Value => "$HomeDir/var/ssl/private"
#);

# check if openssl is located there
if ( !-e $Self->{ConfigObject}->Get('SMIME::Bin') ) {

    # maybe it's a mac with macport
    if ( -e '/opt/local/bin/openssl' ) {
        $Self->{ConfigObject}->Set( Key => 'SMIME::Bin', Value => '/opt/local/bin/openssl' );
    }
}

# create crypt object
$Self->{CryptObject} = Kernel::System::Crypt->new(
    %{$Self},
    CryptType => 'SMIME',
);

if ( !$Self->{CryptObject} ) {
    print STDERR "NOTICE: No SMIME support!\n";
    return;
}

my %Search = (
    1 => '<EMAIL>',
    2 => '<EMAIL>',
);

my %Check = (
    1 => {
        Modulus =>
            'B5D12B210C8EF3E6B404162157022CEFF46AF6519571F985C116A3CF096B5BD9DBE306CA6683221F08858C8BA1422F934916FE29EF89DA1F1DD55AA47443F796CB882843E16CB4F722F8038768B6FDCE8F4ADEC5E81DB46F9B300A765737B698FC0B7D1E57410BCF810E4B3B4F74FD5C805378879E8C23CD5CB6A0A160AE42E9',
        EndDate => 'Mar 29 11:20:56 2012 GMT',
        Subject =>
            '  C= DE ST= Bayern L= Straubing O= OTRS AG CN= unittest emailAddress= <EMAIL>',
        Hash         => '980a83c7',
        Private      => 'No',
        Serial       => 'serial=D51FC7523893BCFD',
        ShortEndDate => '2012-03-29',
        Type         => 'cert',
        Fingerprint  => 'fc00:db20:35b:7399::5:29:8A:3E:C3:19:51:33:1C:73:7F:2C:0B',
        Issuer =>
            'issuer=  /C= DE/ST= Bayern/L= Straubing/O= OTRS AG/CN= unittest/emailAddress= <EMAIL>',
        Email          => '<EMAIL>',
        StartDate      => 'Feb 19 11:20:56 2008 GMT',
        ShortStartDate => '2008-02-19',
    },
    2 => {
        Modulus =>
            'C37422BAB1D6CDE930ED44E79C4D3BD3BECBD4E391FB80C3FC74B639A926D670FDDF6A75EBC304E42FD83311C64356C3DF4E468484CF0A71CAACA333BB99B1ACF418B72020A4D44FA28DF97F0DC2E8D64A0926673FBAC1F29A669E6F3776601CC27937A3212228856CAB9396923B60998198FFD2BB10E8667C02C66F11BA5787',
        EndDate => 'Mar 29 11:32:20 2012 GMT',
        Subject =>
            '  C= DE ST= Bayern L= Straubing O= OTRS AG CN= unittest2 emailAddress= <EMAIL>',
        Hash         => '999bcb2f',
        Private      => 'No',
        Serial       => 'serial=9BCC39BD2A958C37',
        ShortEndDate => '2012-03-29',
        Fingerprint  => '3F:EE:1A:D2:E1:29:06:03:BF:AB:18:8C:F4:BA:E0:9C:FD:47:5D:0A',
        Type         => 'cert',
        Issuer =>
            'issuer=  /C= DE/ST= Bayern/L= Straubing/O= OTRS AG/CN= unittest2/emailAddress= <EMAIL>',
        Email          => '<EMAIL>',
        StartDate      => 'Feb 19 11:32:20 2008 GMT',
        ShortStartDate => '2008-02-19',
    },
    'cert-1' => '-----<KEY>
',
    'cert-2' => '-----BEGIN CERTIFICATE-----
<KEY>iOlfs/25GVflLPh7haPC
/4ruQw==
-----END CERTIFICATE-----
'
);

my $TestText = 'hello1234567890';

for my $Count ( 1 .. 2 ) {
    my @Certs = $Self->{CryptObject}->Search(
        Search => $Search{$Count},
    );
    $Self->False(
        $Certs[0] || '',
        "#$Count Search()",
    );

    # add certificate ...
    my $CertString = $Self->{MainObject}->FileRead(
        Directory => $Self->{ConfigObject}->Get('Home') . "/scripts/test/sample/",
        Filename  => "SMIMECertificate-$Count.asc",
    );
    my $Message = $Self->{CryptObject}->CertificateAdd(
        Certificate => ${$CertString},
    );

    $Self->True(
        $Message || '',
        "#$Count CertificateAdd()",
    );

    @Certs = $Self->{CryptObject}->CertificateSearch(
        Search => $Search{$Count},
    );<commit_msg>* on Windows we have to remove \r characters from the expected certificate   strings (which get inserted by Perl automatically), since openssl does not   produce those<commit_after># --
# SMIME.t - SMIME tests
# Copyright (C) 2001-2008 OTRS AG, http://otrs.org/
# --
# $Id: SMIME.t,v 1.5 2008-05-15 14:11:20 ot Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl-2.0.txt.
# --

use strict;
use warnings;

use Kernel::System::Crypt;

use vars qw($Self);

my $HomeDir = $Self->{ConfigObject}->Get('Home');

# set config
$Self->{ConfigObject}->Set( Key => 'SMIME', Value => 1 );

#$Self->{ConfigObject}->Set(
#    Key => 'SMIME::CertPath', Value => "$HomeDir/var/ssl/certs"
#);
#$Self->{ConfigObject}->Set(
#    Key => 'SMIME::PrivatePath', Value => "$HomeDir/var/ssl/private"
#);

# check if openssl is located there
if ( !-e $Self->{ConfigObject}->Get('SMIME::Bin') ) {

    # maybe it's a mac with macport
    if ( -e '/opt/local/bin/openssl' ) {
        $Self->{ConfigObject}->Set( Key => 'SMIME::Bin', Value => '/opt/local/bin/openssl' );
    }
}

# create crypt object
$Self->{CryptObject} = Kernel::System::Crypt->new(
    %{$Self},
    CryptType => 'SMIME',
);

if ( !$Self->{CryptObject} ) {
    print STDERR "NOTICE: No SMIME support!\n";
    return;
}

my %Search = (
    1 => '<EMAIL>',
    2 => '<EMAIL>',
);

my %Check = (
    1 => {
        Modulus =>
            'B5D12B210C8EF3E6B404162157022CEFF46AF6519571F985C116A3CF096B5BD9DBE306CA6683221F08858C8BA1422F934916FE29EF89DA1F1DD55AA47443F796CB882843E16CB4F722F8038768B6FDCE8F4ADEC5E81DB46F9B300A765737B698FC0B7D1E57410BCF810E4B3B4F74FD5C805378879E8C23CD5CB6A0A160AE42E9',
        EndDate => 'Mar 29 11:20:56 2012 GMT',
        Subject =>
            '  C= DE ST= Bayern L= Straubing O= OTRS AG CN= unittest emailAddress= <EMAIL>',
        Hash         => '980a83c7',
        Private      => 'No',
        Serial       => 'serial=D51FC7523893BCFD',
        ShortEndDate => '2012-03-29',
        Type         => 'cert',
        Fingerprint  => 'E1:FB:F1:3E:6B:83:9F:C3:29:8A:3E:C3:19:51:33:1C:73:7F:2C:0B',
        Issuer =>
            'issuer=  /C= DE/ST= Bayern/L= Straubing/O= OTRS AG/CN= unittest/emailAddress= <EMAIL>',
        Email          => '<EMAIL>',
        StartDate      => 'Feb 19 11:20:56 2008 GMT',
        ShortStartDate => '2008-02-19',
    },
    2 => {
        Modulus =>
            'C37422BAB1D6CDE930ED44E79C4D3BD3BECBD4E391FB80C3FC74B639A926D670FDDF6A75EBC304E42FD83311C64356C3DF4E468484CF0A71CAACA333BB99B1ACF418B72020A4D44FA28DF97F0DC2E8D64A0926673FBAC1F29A669E6F3776601CC27937A3212228856CAB9396923B60998198FFD2BB10E8667C02C66F11BA5787',
        EndDate => 'Mar 29 11:32:20 2012 GMT',
        Subject =>
            '  C= DE ST= Bayern L= Straubing O= OTRS AG CN= unittest2 emailAddress= <EMAIL>',
        Hash         => '999bcb2f',
        Private      => 'No',
        Serial       => 'serial=9BCC39BD2A958C37',
        ShortEndDate => '2012-03-29',
        Fingerprint  => '3F:EE:1A:D2:E1:29:06:03:BF:AB:18:8C:F4:BA:E0:9C:FD:47:5D:0A',
        Type         => 'cert',
        Issuer =>
            'issuer=  /C= DE/ST= Bayern/L= Straubing/O= OTRS AG/CN= unittest2/emailAddress= <EMAIL>',
        Email          => '<EMAIL>',
        StartDate      => 'Feb 19 11:32:20 2008 GMT',
        ShortStartDate => '2008-02-19',
    },
    'cert-1' => '-----BEGIN CERTIFICAT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FzbVnIWGb3lhDcjKiLjshR7tUSs4eeR
w1mJrbFPWksw+fr6vUQwtU0YaNU0mKhE/e0WGDQw6d3/sU/XCM6zKEdrRDum
-----END CERTIFICATE-----
',
    'cert-2' => '-----BEGIN CERTIFICATE-----
<KEY>
-----END CERTIFICATE-----
'
);

# remove \r that will have been inserted on Windows automatically
if ( $^O =~ m{Win}i ) {
    $Check{'cert-1'} =~ tr{\t}{}d;
    $Check{'cert-2'} =~ tr{\t}{}d;
}

my $TestText = 'hello1234567890';

for my $Count ( 1 .. 2 ) {
    my @Certs = $Self->{CryptObject}->Search(
        Search => $Search{$Count},
    );
    $Self->False(
        $Certs[0] || '',
        "#$Count Search()",
    );

    # add certificate ...
    my $CertString = $Self->{MainObject}->FileRead(
        Directory => $Self->{ConfigObject}->Get('Home') . "/scripts/test/sample/",
        Filename  => "SMIMECertificate-$Count.asc",
    );
    my $Message = $Self->{CryptObject}->CertificateAdd(
        Certificate => ${$CertString},
    );

    $Self->True(
        $Message || '',
        "#$Count CertificateAdd()",
    );

    @Certs = $Self->{CryptObject}->CertificateSearch(
        Search => $Search{$Count},
    );
{'fraction_non_alphanumeric': 0.1543515617103002, 'fraction_numerical': 0.11745678762761548, 'mean_word_length': 3.1977089520577007, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 168, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4399668', 'n_tokens_mistral': 4916, 'n_tokens_neox': 4219, 'n_words': 622}