bool CFileDialog::CoreHandleKey(chtype key)
{
    if (CDialog::CoreHandleKey(key))
        return true;
    
    if (key == KEY_F(2))
    {
        std::string newdir = InputBox(GetTranslation("Enter name of new directory"), "", 1024);
        
        if (newdir.empty())
            return true;
        
        if (newdir[0] != '/')
            newdir = m_Directory + '/' + newdir;
        
        try
        {
            if (MKDirNeedsRoot(newdir))
            {
                LIBSU::CLibSU suhandler;
                std::string passwd = AskPassword(suhandler);
                MKDirRecRoot(newdir, suhandler, passwd.c_str());
                passwd.assign(passwd.length(), 0);
            }
            else
                MKDirRec(newdir);
            
            OpenDir(newdir);
        }
        catch(Exceptions::CExIO &e)
        {
            WarningBox(e.what());
        }
            
        return true;
    }
    
    return false;
}
Пример #2
0
OP_STATUS PKCS_11_Token::GetCertificateFromToken()
{
	CK_RV status;
	CK_CERTIFICATE_TYPE cert_type;
	CK_ULONG	cert_object_type = CKO_CERTIFICATE;
	//CK_ULONG key_class, key_alg;
	//CK_BBOOL key_signflag, key_signrflag;
	CK_ATTRIBUTE search_for[] = {
		{CKA_CLASS, &cert_object_type, sizeof(cert_object_type)}
	};
	CK_ATTRIBUTE get_type[] = {
		{CKA_CERTIFICATE_TYPE, &cert_type, sizeof(CK_CERTIFICATE_TYPE)}
	};
	CK_ATTRIBUTE certificate_value[] = {
		{CKA_VALUE, NULL_PTR, 0}
	};
	/*
	CK_ATTRIBUTE key_att[] = {
		{CKA_CLASS,		&key_class,	sizeof(key_class)},
		{CKA_KEY_TYPE,	&key_alg,	sizeof(key_alg)}
	};	
	CK_ATTRIBUTE key_flags[] = {
		{CKA_SIGN,		&key_signflag,	sizeof(key_signflag)},
		{CKA_SIGN_RECOVER,	&key_signrflag,	sizeof(key_signrflag)}
	};	
	*/
	//CK_OBJECT_HANDLE key = CK_INVALID_HANDLE;
	CK_OBJECT_HANDLE object = CK_INVALID_HANDLE;
	CK_ULONG object_count=0;
	//CK_ULONG key_count=0;

	if(!CheckSession())
		return OpStatus::ERR;


	if(master->MustLoginForCertificate() && NeedLogIn())
	{
		SSL_secure_varvector32 password;

#define MSG_SECURE_ASK_PINCODE Str::SI_MSG_SECURE_ASK_PASSWORD
		if(!NeedPin() || AskPassword(MSG_SECURE_ASK_PINCODE, password, SSL_present_hwnd))
		{
			RETURN_IF_ERROR(Login(password));
		}
	}

	/*
	key_class = CKO_PRIVATE_KEY;
	key_alg = CKK_RSA;

	status = functions->C_FindObjectsInit(session, key_att, ARRAY_SIZE(key_att));
	RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));

	status = functions->C_FindObjects(session, &key, 1, &key_count);
	RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));

	if(key_count == 0)
		return OpStatus::OK;

	key_signflag = FALSE;
	key_signrflag = FALSE;

	status = functions->C_GetAttributeValue(session, key, key_flags, ARRAY_SIZE(key_flags));
	RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));

	status = functions->C_FindObjectsFinal(session);
	RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));
	if(!key_signflag)
		return OpStatus::OK;

	*/

	status = functions->C_FindObjectsInit(session, search_for, ARRAY_SIZE(search_for));
	RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));

	do{
		status = functions->C_FindObjects(session, &object, 1, &object_count);
		RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));
		
		if(object_count)
		{
			status = functions->C_GetAttributeValue(session, object, get_type, 1);
			RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));
			
			if(cert_type != CKC_X_509 && cert_type != CKC_X_509_ATTR_CERT)
				continue; // Do not handle unsupported certificates
			
			status = functions->C_GetAttributeValue(session, object, certificate_value, 1);
			RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));
			if(((CK_LONG) certificate_value[0].ulValueLen) == -1 || certificate_value[0].ulValueLen ==0)
				continue;
			
			certificate.Resize(1);
			if(certificate.Error())
				return OpStatus::ERR;
			
			certificate[0].Resize(certificate_value[0].ulValueLen);
			if(certificate.Error())
				return OpStatus::ERR;
			
			certificate_value[0].pValue = certificate[0].GetDirect();
			certificate_value[0].ulValueLen = certificate[0].GetLength();
			
			status = functions->C_GetAttributeValue(session, object, certificate_value, 1);
			RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));
			
			break;
		}

	}while(object_count);

	status = functions->C_FindObjectsFinal(session);
	RETURN_IF_ERROR(master->TranslateToOP_STATUS(status));

	return OpStatus::OK;
}