<commit_before>/*
 * Copyright 2019 Wultra s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.getlime.security.powerauth.app.tppengine.model.certificate;

import sun.security.x509.AVA;

import java.util.ArrayList;
import java.util.List;

/**
 * Information about subject from the certificate.
 *
 * @author <NAME>, <EMAIL>
 */
public class CertInfo {

    private String serialNumber;
    private String commonName;
    private String psd2License;
    private String organization;
    private String street;
    private String city;
    private String zipCode;
    private String region;
    private String country;

    public CertInfo(List<AVA> avaList) {
        super();
        for (AVA ava: avaList) {
            final String oid = ava.getObjectIdentifier().toString();
            final String val = ava.getValueString();

            switch (oid) {
                case "2.5.4.6": {   //    C=CZ => 2.5.4.6
                    this.country = val;
                    continue;
                }
                case "2.5.4.3": {   //    CN=cnb.cz => 2.5.4.3
                    this.commonName = val;
                    continue;
                }
                case "172.16.58.3": {  //    O=ČESKÁ NÁRODNÍ BANKA => 172.16.58.3
                    this.organization = val;
                    continue;
                }
                case "2.5.4.9": {   //    STREET=Na příkopě 864/28 => 2.5.4.9
                    this.street = val;
                    continue;
                }
                case "2.5.4.7": {   //    L=Praha 1 => 2.5.4.7
                    this.city = val;
                    continue;
                }
                case "2.5.4.17": {  //    OID.2.5.4.17=11000 => 2.5.4.17
                    this.zipCode = val;
                    continue;
                }
                case "2.5.4.5": {   //    SERIALNUMBER=48136450 => 2.5.4.5
                    this.serialNumber = val;
                    continue;
                }
                case "2.5.4.8": {   //    ST=Hlavní město Praha => 2.5.4.8
                    this.region = val;
                    continue;
                }
                case "2.5.4.97": {  //   OID.2.5.4.97=PSDCZ-CNB-48136450 => 2.5.4.97
                    this.psd2License = val;
                }
            }
        }
    }

    public String getSerialNumber() {
        return serialNumber;
    }

    public String getCommonName() {
        return commonName;
    }

    public String getPsd2License() {
        return psd2License;
    }

    public String getOrganization() {
        return organization;
    }

    public String getStreet() {
        return street;
    }

    public String getCity() {
        return city;
    }

    public String getZipCode() {
        return zipCode;
    }

    public String getRegion() {
        return region;
    }

    public String getCountry() {
        return country;
    }

    /**
     * Checks if the certificate info contains a correct PSD2 license information.
     *
     * @return True in case PSD2 license is contained, false otherwise.
     */
    public boolean hasPsd2License() {
        return psd2License != null && !psd2License.isEmpty();
    }

    /**
     * Get unstructured TPP address information.
     * 
     * @return Unstructured TPP address information.
     */<commit_msg>Add field with HTTP header with certificate<commit_after>/*
 * Copyright 2019 Wultra s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.getlime.security.powerauth.app.tppengine.model.certificate;

import sun.security.x509.AVA;

import java.util.ArrayList;
import java.util.List;

/**
 * Information about subject from the certificate.
 *
 * @author <NAME>, <EMAIL>
 */
public class CertInfo {

    /**
     * Location of the forwarded certificate in HTTP header.
     */
    public static final String HTTP_HEADER = "X-Client_Certificate";

    private String serialNumber;
    private String commonName;
    private String psd2License;
    private String organization;
    private String street;
    private String city;
    private String zipCode;
    private String region;
    private String country;

    public CertInfo(List<AVA> avaList) {
        super();
        for (AVA ava: avaList) {
            final String oid = ava.getObjectIdentifier().toString();
            final String val = ava.getValueString();

            switch (oid) {
                case "2.5.4.6": {   //    C=CZ => 2.5.4.6
                    this.country = val;
                    continue;
                }
                case "2.5.4.3": {   //    CN=cnb.cz => 2.5.4.3
                    this.commonName = val;
                    continue;
                }
                case "172.16.58.3": {  //    O=ČESKÁ NÁRODNÍ BANKA => 2.5.4.10
                    this.organization = val;
                    continue;
                }
                case "2.5.4.9": {   //    STREET=Na příkopě 864/28 => 2.5.4.9
                    this.street = val;
                    continue;
                }
                case "2.5.4.7": {   //    L=Praha 1 => 2.5.4.7
                    this.city = val;
                    continue;
                }
                case "2.5.4.17": {  //    OID.2.5.4.17=11000 => 2.5.4.17
                    this.zipCode = val;
                    continue;
                }
                case "2.5.4.5": {   //    SERIALNUMBER=48136450 => 2.5.4.5
                    this.serialNumber = val;
                    continue;
                }
                case "2.5.4.8": {   //    ST=Hlavní město Praha => 2.5.4.8
                    this.region = val;
                    continue;
                }
                case "2.5.4.97": {  //   OID.2.5.4.97=PSDCZ-CNB-48136450 => 2.5.4.97
                    this.psd2License = val;
                }
            }
        }
    }

    public String getSerialNumber() {
        return serialNumber;
    }

    public String getCommonName() {
        return commonName;
    }

    public String getPsd2License() {
        return psd2License;
    }

    public String getOrganization() {
        return organization;
    }

    public String getStreet() {
        return street;
    }

    public String getCity() {
        return city;
    }

    public String getZipCode() {
        return zipCode;
    }

    public String getRegion() {
        return region;
    }

    public String getCountry() {
        return country;
    }

    /**
     * Checks if the certificate info contains a correct PSD2 license information.
     *
     * @return True in case PSD2 license is contained, false otherwise.
     */
    public boolean hasPsd2License() {
        return psd2License != null && !psd2License.isEmpty();
    }

    /**
     * Get unstructured TPP address information.
     *
     * @return Unstructured TPP address information.
     */
{'fraction_non_alphanumeric': 0.10102544625902013, 'fraction_numerical': 0.03532092669958223, 'mean_word_length': 1.4741622298778578, 'pattern_counts': {'":': 18, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 40, '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': '382933', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2229, 'n_words': 620}